Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery selector - selecting all span tags with id not equal to something

Tags:

jquery

I want to select all HTML <span> elements that don't have an id equal to x and hide them them. Is this possible? I think you have to use the :not selector but I can't work it out:

$('span:not(#x').attr('style', "display: none;");

Any ideas? Thank you :).

like image 340
ale Avatar asked Nov 30 '22 15:11

ale


2 Answers

You just forgot a ).

I made a fiddle to show you. http://jsfiddle.net/3U8tD/

$('span:not(#x)').attr('style', "display: none;");
like image 121
Filip Avatar answered Dec 10 '22 21:12

Filip


$('span[ID!="x"]').attr('style', "display: none;");

sets the style attribute of all spans, wich has NOT the id x, to none.

hope this helps

like image 34
dknaack Avatar answered Dec 10 '22 21:12

dknaack