Trouble understanding children() and :first in jQuery -


i confused how selection of element in jquery works using children() , :first custom class?

for instance, in jsfiddle, code ul > li {hello nest} not class .emphasis first-child of top level ul gets it. expected inner li class.

the commented out line in jquery code works expect to.

:first selector returns first matched item among selected

so

$('ul').children('li:first').addclass('emphasis'); 

selects children of ul li , takes first of them.

whereas

 $('ul > li:first-child').addclass('emphasis'); 

takes li direct children of ul , takes every first child of matched set.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

php - Boolean search on database with 5 million rows, very slow -

css - Text drops down with smaller window -