"ALL but NOT" jQuery selector

"ALL but NOT" jQuery selector

"ALL but NOT" jQuery selector

jQuery Oct 30, 2022

We can select (using jQuery) all the divs in a HTML markup as follows:


But If we want to exclude a particular div (say having id="myid") from the above selection. Then too it's simple, here is the solution.

Use .not selector from jQuery as following.


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:


Both selectors do the same task; however, :not() is quicker, likely because jQuery's Sizzle selector engine can optimise it to perform as a native. calling .querySelectorAll().



Anurag Deep

Logical by Mind, Creative by Heart