Why does this brute force not work for me:

$('#div').children('li').children('a').each(index) { //тело цикла } 

?

    2 answers 2

    And why such a perversion?

     $('#div>li>a').each(function(index){ /* code */ }); 
    • this is not the same :) $ ('# div> li> a'). each (function (index) {/ * code * /}); then - Syabrowka
    • Accepted) Never used children() , find() always enough. - Sh4dow
    • in theory, children () should work faster. It searches strictly among direct descendants. It makes sense to use in certain cases. - Syabrowka

    Maybe because of a syntax error?

     $('#div>li>a').each(function(index){ тело цикла })