views:

60

answers:

4

I'm trying to find all LIs with name=checked and hide() them, but this doesn't seem to be working:

    $('li').attr("name","checked").hide();

<li name="unchecked" style="display: inline;"><a href="/">Home</a></li>

Any ideas?

+10  A: 

This should do it:

$('li[name="checked"]').hide();

Doing:

$('li').attr("name","checked").hide();

will change the name of all lis to checked and then hide them, so it is wrong...

Web Logic
+3  A: 

Test the name attribute in the selector:

$('li[name="checked"]').hide();
BoltClock
A: 

just to add to the correct answers above, your usage is to set the value of the attribute specified in the first argument to the value specified in the second.

Pharabus
+1  A: 

and another one (choose any version of a query)

$('li').filter('[name=checked]').hide();
Jenechka