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 trial

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Perform: Part 3

Justin Goldby
seal-mask
.a{fill-rule:evenodd;}techdegree
Justin Goldby
Full Stack JavaScript Techdegree Student 12,754 Points

Is 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
Steven Parker
229,708 Points

Be 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.

Kai-Ting Lin
Kai-Ting Lin
5,712 Points

I 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?

Alexius Yap
Alexius Yap
9,608 Points

i 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?