What is exactly do the eventPrevent();


I got that to prevent from click action something default but what is that?

Is used to prevent what event on a button or something?

What situation need it or not need it to set on links?



The correct name is event.preventDefault()

If an HTML element has a default action, i.e. it’s default behavior (for example, an href link, or a form submit button) and for some reason you want to stop or prevent that from happening, you can invoke the preventDefault() for that html element.

For example, if a user clicks on the Submit button of a form, the normal behavior is control (and the form contents) are passed to the page that is specified in the form action parameter. If you want to stop that from happening, for example, you may want to do some form validation first (checking if all fields are inputted, or checking some values if it meets your criteria), you check the fields first, and if something doesn’t meet your criteria (or there’s a missing field input), then you can prevent the form from being submitted.

Another example of usage, for example: the default behavior of an href link is to load a new page. What if you want to disable that, and instead load a popup window instead, or have something happen to the page (display a hidden div, hide a div, etc).

Thanks! Great and understand answer.