Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialcarine todmia
6,071 Pointsi thought $(".selected") was considered improper syntax for jquery
i know in plain javascript i can add the .selected to identify a class but i was almost sure when writing jquery you dont include this. Can someone help me with this understanding or am i confusing this with some other rule?
2 Answers
Pavle Lucic
10,801 Pointscarine todmia hi,
Maybe you get confused by this code
$(".selected").removeClass("selected");
The first part $(".selected") - it is Jquery selector (almost same as you would select elements in CSS). It selects html element with class selected and create jquery object from him.
Another part is .removeClass("selected") - it is Jquery method (there is not dot at the end). So every object can have methods. This method removeClass, removes class selected from $(".selected") html element.
David B Dinkins
71,472 PointsThe $("")
syntax is the most common way of selecting the elements in the DOM with jQuery. You can use it to select an element using HTML tag names the way you do in CSS:
$("div a:link").show();
You can also use it select an element by its class or id:
$(".selected").hide()
// or
$("#form-submit").hide().
carine todmia
6,071 Pointscarine todmia
6,071 Pointsso what is the actual object in this case
Pavle Lucic
10,801 PointsPavle Lucic
10,801 Points$(".selected") - It is a object.