Simple:
$('div').not('#myid');
Using .not()
will remove elements matched by the selector given to it from the set returned by $('div')
.
You can also use the :not()
selector:
$('div:not(#myid)');
Both selectors do the same thing, however :not()
is faster, presumably because jQuery’s selector engine Sizzle can optimise it into a native .querySelectorAll()
call.