Tuesday, December 18, 2012

javascript – jQuery Click Event PreventDefault

If I have an #code#PmE8#/code# tag:



<a id=\"delete-event\" href=\"/delete/1234\">Delete</a>


And some javascript which prompts to confirm the delete:



$(\"#delete-event\").click(function(e) {
e.preventDefault();

bootbox.confirm(\"Are you sure you wish to delete this?\", function(confirmed) {
if(confirmed) {
return true;
}
});
});


I thought doing e.preventDefault() would prevent the a href from firing, but its not. When I click the a tag it simply goes to the url, without executing the javascript. How can I make this work?


Thanks.






Rating: 5 out of 5 based on 3 ratings



The post javascript – jQuery Click Event PreventDefault appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-jquery-click-event-preventdefault.html

No comments:

Post a Comment