I want to capture clicks outside an HTML tag. For example I have this HTML:
<body>
<div>
<ul>
<li id="button">
</li>
</ul>
</div>
</body>
The #button is a smallest square in the middle of the page. Once user clicks outside it something happens, click inside and nothing should happen.
This JS doesn't work because of event propagation:
jQuery('*').not('li#button').click(...);
so my click event eventually fires on ul, div and body triggering the event. I can't use this:
jQuery('*').click(function(e) {
e.stopPropagation();
if(e.(...)) {}
})
because other events on the page stop working.
What's the other way of achieving this?