I'm asked that a click anywhere in a div does a specific action (say collapse it) unless the click was on a link, a button, etc...
Basically, I'd like the reverse of event.preventDefault()
.
Is there a good and easy way to do this?
I'm looking for a generic solution here; I would like to not assume much about the content of the div.
Might look like:
<div id="click_me>
<p>Clicking here should do stuff
<a href="http://stackoverflow.com">but not here, nor on the following image</a>
<a href="/xyz"><img url="/icon.png"/></a>
imagine buttons... input areas, ...
</p>
</div>
With the following Javascript:
$("#click_me").click(function(){
if(black_magic) {
$("#click_me").toggleClass("collapsed");
}
});