When I use event.preventDefault()
on a link it works, however when I use it on a button doesn't!
My code:
<a id=link href=http://www.google.com>link</a>
<button id=button onclick=alert('an alert')>button</button>
$('#link').click(function(event){
event.preventDefault();
});
$('#button').click(function(event){
event.preventDefault();
});
Link action is cancelled, but when I click on the button, still executes the onClick
action.
Any help? what I want to do is to prevent the button onClick
action without changing the button html (I know how to do
$('#button').removeAttr('onclick');