0

Possible Duplicate:
jQuery: Target all except ___?

I've got a script that detects clicks on every element on the page. I'd like that to run on everything except a specific div and its children.

I've tried doing this using the :not selector, but don't really understand how to use that effectively, so I'm not sure if that's the right way to go or not.

Here's some sample code:

<div id="clickme">This is good stuff</div>

<div id="dontclickme">This should not get selected</div>

I'm currently using $("*") for my selector. Is there a way to use that to detect if it's the second div, or any of its children?

Community
  • 1
  • 1
user1146223
  • 209
  • 4
  • 14

2 Answers2

0

Select all divs, but not .class:

$("div").not(".class")

Works with other selectors too.

aNewStart847
  • 1,086
  • 7
  • 15
0

You can use .filter() with .closest() to check if element has a certain id or element is a children/descendant of element with certain id...

$('body *').filter(function(i, v) {        
    return $(v).closest('#dontclickme').length == 0;
})

http://jsfiddle.net/wirey00/7JE7x/

wirey00
  • 33,517
  • 7
  • 54
  • 65