Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - select elements that are not within a ID

How can I select all elements that have a title attribute, but are not contained by a element with the #boo ID ?

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

but not elements which are in #boo :)

like image 971
Alex Avatar asked Nov 28 '22 18:11

Alex


2 Answers

$("[title]").not("#boo [title]").each()

demo

and as a side note, when you use id in getting the element, it is faster if you don't prefix the element's tag. For example, just use #boo instead of div#boo. demo <-- try to look at the console of firebug for time comparison.

like image 98
Reigel Avatar answered Dec 05 '22 14:12

Reigel


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

like image 44
sevenseacat Avatar answered Dec 05 '22 13:12

sevenseacat