Say I have the following code:
<div onclick='location.href="http://www.example.com/"'>
<a href='#' onclick='alert("blah")'>click</a>
</div>
Is there a way to only have the anchor evaluated when I click the ‘click’ text and not have the div’s onclick evaluated?
You can stop event propagation by returning
falsefrom the anchor’s click event handler.You’ve tagged this question with jQuery. In that case, you should be using unobtrusive Javascript so:
with:
is a much cleaner solution.