Preventing the Default Action
Learn about preventing the default action of an element and explore its use cases.
We'll cover the following
What is eventObj.preventDefault()
?
In jQuery, we can prevent an element’s default behavior by calling the eventObj.preventDefault()
method inside the event handler function.
For example, in the page HTML below, we have a hyperlink (<a>
) element with the attribute href
set to "https://www.educative.come"
. By default, if we click on this element, we are redirected to the link within href
.
Get hands-on with 1200+ tech skills courses.