Jaaaaabbb
Jaaaaabbb

Reputation: 121

prevent all elements within a div from being selected. \

i am trying to prevent all elements within a div from being selected. this is not working.

$('*').not('#someid > *')

Upvotes: 0

Views: 273

Answers (2)

Seb
Seb

Reputation: 25147

The only problem with your approach is that you're asking for immediate children. If you remove the > it should work fine:

$('*').not('#someid *');

Upvotes: 1

nickf
nickf

Reputation: 546005

Use filter():

$("*").filter(function() {
    return !$(this).closest("#someid").length;
})

...actually doing some more testing, this should also work:

$("*:not(#someid *)")

Upvotes: 1

Related Questions