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 trialJustin Goldby
Full Stack JavaScript Techdegree Student 12,754 PointsIs selected a pseudo class?
So I guess where I am confused is that the browser knows to apply the selected class to which ever list item we click, is that just a pseudo class like visited etc??
2 Answers
Steven Parker
231,275 PointsBe aware that :selected is a jQuery extension and not part of the CSS specification. So it operates as a pseudo-class for JQuery selectors only.
Also note that it only applies to <option>
elements. It does not work for checkboxes or radio inputs; for those use :checked instead.
Alexius Yap
9,608 Pointsi was also baffled by this, how did the selected class (not the property) get automatically assigned to each list item once they were clicked? was there a code added off screen? i mean, i know how you can achieve this by using the addClass method but i never noticed the instructor do that or anything equivalent for that matter. did i miss anything?
Justin Goldby
Full Stack JavaScript Techdegree Student 12,754 PointsJustin Goldby
Full Stack JavaScript Techdegree Student 12,754 PointsThank you!
Kai-Ting Lin
5,712 PointsKai-Ting Lin
5,712 PointsI have the same question. I understand well that :selected is for <option> element. What I don't understand is the HTML part, how does the <li> item get automatically the class of "selected" once we click on it? Does that mean if we remove the JQuery, it won't work on purely HTML document?