Reputation: 68470
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
:)
Upvotes: 4
Views: 2844
Reputation: 4984
I've had to do this before and used something like:
$(":not(#boo) > [title]")
Upvotes: 1
Reputation: 65264
$("[title]").not("#boo [title]").each()
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.
Upvotes: 9
Reputation: 303224
There are may ways to skin this cat. Here are two more:
$('[title]:not(#boo *[title])');
$('[title]').not('#boo *[title]');
Upvotes: 2
Reputation: 35276
$('[title]').filter(function(){return $(this).parents('#boo').length === 0;})
Upvotes: 3