preventDefault() Event Method Last Updated : 30 Sep, 2024 Comments Improve Suggest changes Like Article Like Report The preventDefault() method is used to prevent the browser from executing the default action of the selected element. It can prevent the user from processing the request by clicking the link. Syntax:event.preventDefault()Parameters: It does not accept any parameter. The event is used to denote the event or action by the user in the response to which the method works. Example: This code will prevent the browser from going to another page. html <!DOCTYPE html> <html lang="en"> <head> <title> preventDefault() Event Method </title> <!-- INCLUDE THE JQUERY CDN --> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("a").click(function (event) { event.preventDefault(); alert("prevented"); }); }); </script> </head> <body> <p>Click the link:</p> <a href="https://www.google.com">GOOGLE</a> </body> </html> Output:Example: This code will prevent the browser from redirecting the page to another PHP file. html <!DOCTYPE html> <html lang="en"> <head> <title> preventDefault() Event Method</title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#submit").click(function (event) { event.preventDefault(); alert("Action is prevented"); }); }); </script> </head> <body> <form action="submit.php"> <input type="text" placeholder="enter username"> <input id="submit" type="submit" name="submit"> </form> </body> </html> Output: Comment More infoAdvertise with us Next Article preventDefault() Event Method _shreya_garg_ Follow Improve Article Tags : JavaScript Web Technologies JQuery Similar Reads jQuery event.preventDefault() Method The jQuery preventDefault() Method is used to stop the default action of the selected element to occur. It is also used to check whether preventDefault() method is called for the selected element or not. Syntax: event.preventDefault()Parameter: It does not accept any parameter. Example 1: This examp 2 min read jQuery event.isDefaultPrevented() Method jQuery isDefaultPrevented() Method is an inbuilt method that checks whether the preventDefault() method was called for the event. This method returns a boolean value. It returns True if preventDefault() is called on the event, False otherwise. Syntax:event.isDefaultPrevented()Parameters: It accepts 2 min read jQuery Event Methods Complete Reference An event refers to the actions performed by the site visitor during their interactivity with the website (or webpage). There can be various types of events such asThe user clicks on the button.The user moves the mouse pointer over an image.The user pressed any key from the keyboard, etc.Syntax:$(sel 6 min read jQuery event.stopPropagation() Method The jQuery event.stopPropagation() method is an inbuilt method which is used to stop the windows propagation. In the DOM tree when setting an event with the child element and the parent element as well then if you hit on the child element event it will call both child and the parent element as well. 2 min read jQuery undelegate() Method The jQuery undelegate() method is an inbuilt method that is used to remove the specified event handler from the selected element. Syntax: $(selector).undelegate(selector, event, function)Parameters: This method accepts three parameters as mentioned above and described below: selector: It is an optio 2 min read Like