Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

let div disappear, onClick "everywhere but ..."

Tags:

jquery

I got a DIV positioned absolute above other elements on the page and I want it to disappear when clicked somewhere but NOT inside that absolute positioned div (or one of its child elements).

I'm using jQuery's event propagation ($(document).on(...)) for all click events on page.

I would like to have a generic solution, not white- or blacklists of tags, classes please.

I'm not looking for a 'put a transparent layer in between absolute DIV and other content' solution, that would be my last ressort workaround.

Thx

like image 621
ezmilhouse Avatar asked Dec 06 '25 05:12

ezmilhouse


1 Answers

$('html').click(function() {
  //Hide whatever you want to hide
});

$('#your_div').click(function(e){
  e.stopPropagation();
});

you could also try this.

like image 149
Marius Ilie Avatar answered Dec 07 '25 19:12

Marius Ilie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!