How can I stop an onclick event from firing for parent element when child is clicked?

For your first question: IE doesn’t support stopPropagation(), instead you should use e.cancelBubble = true. Just do a function check first to find out which method you should use (if (e.stopPropagation) {code}).

For your second question: Maybe include a second div that handles the click event?

<div><img src="https://stackoverflow.com/questions/985389/image.jpg"/></div>
<div style="position:absolute" onclick="doSomething();"></div>

and then position the second div correctly

Leave a Comment