Variable and jQuery selector

To change all the direct children to red you can use

menu.children('li').css("color","red");

If you require all li's within the ul (nested ul>li>ul>li) then use .find

menu.find('li').css("color","red");

You should run something like this:

menu.children('li').css('color', 'red');

The problem is that menu is an object and adding string to an object return NaN (in FF) which cannot be used as a selector.


What you're doing wrong is adding a jQuery object with a string. Try:

var menu = $('ul');
menu.find('li').css('color', 'red');