I am asked to click anywhere in the div to do a certain action (say, collapse it), unless the click was on a link, button, etc.
Basically, I need the flip side of event.preventDefault() .
Is there a good and easy way to do this?
I am looking for a general solution here; I would not like to talk a lot about the content of the div.
It might look like this:
<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"); } });
source share