JQuery - select items that are not included in the identifier

How can I select all elements with title attribute but not contained in element with id #boo ?

like $("*[title]").each()...

but not the elements that are in #boo :)

+4
source share
6 answers
 $("[title]").not("#boo [title]").each() 

demonstration

and as a side note, when you use id to get an element, it is faster if you don't prefix the element tag. For example, use #boo instead of div#boo . demo - try looking at the firebug console for time comparisons.

+9
source

$('*:not(#boo) *[title]'); must work.

+6
source
 $('[title]').filter(function(){return $(this).parents('#boo').length === 0;}) 
+3
source

Are there any ways to fool this cat. Here are two more:

 $('[title]:not(#boo *[title])'); $('[title]').not('#boo *[title]'); 
+2
source

I should have done this before and used something like:

 $(":not(#boo) > [title]") 
+1
source

Source: https://habr.com/ru/post/1335790/


All Articles