I am sure this must already have been asked but I can't find it.
<div class=".clickable">
<img src="my-big-button">
Some text maybe
</div>
$(".clickable").click(function(e) {
var el = $(this);
if (el.prop("tagName") == "IMG")
{
el = el.parent("div");
}
el.addClass("selected");
});
I want to put the class on the div. But if the user clicks the image it is the image which is the target in the click event handler. The click event has 'bubbled up'. So my current code detects for this and 'elevates' the handler to the div. But there must be a better way of doing this?