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/
source share