Reputation: 11820
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 :).
Upvotes: 4
Views: 16746
Reputation: 14875
There are at least three ways to do what you need.
$('span:not(#x)').attr('style', "display: none;");
$('span[id!="x"]').attr('style', "display: none;");
$('span').filter(':not(#x)').attr('style', "display: none;");
The most efficient way is $('span[id!="x"]').attr('style', "display: none;");
See http://jsfiddle.net/xpAeK/
Upvotes: 3
Reputation: 60486
$('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
Upvotes: 4
Reputation: 2522
You just forgot a ).
I made a fiddle to show you. http://jsfiddle.net/3U8tD/
$('span:not(#x)').attr('style', "display: none;");
Upvotes: 13
Reputation: 1851
try this
$('span[id!="x"]').attr('style', "display: none;");
Upvotes: 1