 <p>Use <a href="https://developer.mozilla.org/en/docs/Web/API/Event/stopPropagation" rel="nofollow">event.stopPropagation</a> method of <code>Event</code>. There is a mistake in your second code snippet where you do not pass <code>event</code> to the anonymous function. Fixed code:</p> <p><code>&lt;div onclick="(function(e) { e.preventDefault(); e.stopPropagation(); })(event)"&gt;</code></p>