JavaScript JavaScript and the DOM Getting a Handle on the DOM Using CSS Queries to Select Page Elements

Fuad Muhammad
Fuad Muhammad
4,273 Points

Where (odd) and (even) come from? And what is this?

On this section we find something that will be beginner like me confusing. Because on the querySelector we find the (odd) and (even). And on the DOM, I don't see this word anymore. Where is this come from? And for what?

Timothy Acker
Timothy Acker
Front End Web Development Techdegree Graduate 31,247 Points

You need to become familiar with CSS pseudo-classes. These classes are pre-defined. So, in the example given, the odd or even numbered list elements can be selected using :nth-child() pseudo-class with the odd or even keyword, respectively. See link below for more information.

https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes

1 Answer

David Kanwisher
David Kanwisher
9,700 Points

Here is a fiddle of them in action in CSS to add on to what Timothy was saying:

http://jsfiddle.net/thirtydot/K3TuN/1323/

And one in javascript

http://jsbin.com/vaxuyivixo/1/edit?html,js,output