1

I'm looking for a way to do this :

$('*:not(#specific)').on('click',function(e){
  //execute code
});

//or : 

$('*').not('#specific').on('click',function(e){
  //execute code
});

To apply an action on every elements of the DOM but not on my specific div and childs.

But none of thems seems to work.

Basically, I try to set up a system like firebug who can apply an outline to the last children of the over element (this part is ok). But after keep the outline on the element select and open a dialog box. But the dialog box who appears when we click on a DOM element is also a part of this DOM which generate an infinite loop of events. I cannot use my dialog box properly.

Thanks anyway

3 Answers3

1

Try this instead:

$('body *').not('#specific, #specific *').on('click',function(e){
  //execute code
});

This will ignore #specific and any of its children.

Hydrothermal
  • 4,851
  • 7
  • 26
  • 45
0

The second code that you've written is completely valid. You can refer to this answer.

It is basically a :not() selector:

$('*').not('#specific').on('click',function(e){
     //execute code
});
Community
  • 1
  • 1
Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
0

Thanks guys,

$('body *').not('#specific, #specific *').on('click',function(e){
  //execute code
});

Works perfectly.

And if I have to bind a click on #specific, I have to insert inside the previous code...

$('body #specific').on('click',function(e){
  //execute code...
});

Is that correct ?