I have the following code to just test how the e.preventDefault() works.
I would think it would stop the click event from happening.
$(document).ready(function( )
{
$("button").click(function(e)
{
e.preventDefault();
alert('button clicked');
});
});
I have a button. What is the purpose of e.preventDefault().
From what I read, it will prevent the action which in this case is the click.
Note that in the above example, the alert message still show. How does e.preventDefault() work for a button click. I know if it was a hyperlink, it would prevent the hyperlink from going to it target.
preventDefault is to prevent default, browser action. So if you will put something like:
click on links will do nothing. Or on submit button – form won’t be submitted