Reputation: 7563
How can i stop propagation for link?
<script src="http://code.jquery.com/jquery.min.js"></script>
<script>
$(function() {
$("#g").click(function(event){
alert("Link clicked");
event.stopPropagation();
});
});
</script>
<a id="g" href="http://google.com">Google</a>
I want the browser don't go to google, just show alert.
Upvotes: 8
Views: 7059
Reputation: 14967
if you just want to not go to google, just return false.
$("#g").bind('click', function(event){
alert("Link clicked");
return false;
});
Upvotes: 2
Reputation: 349042
You have to use event.preventDefault();
to prevent the default action -navigating to Google- from happening.
Upvotes: 19