Home > event.preventDefault()

jQuery: Difference between event.preventDefault() method and event.stopPropagation() method

event.preventDetault() method: event.preventDetault() method  stops default action of the element, e.g. In preventDefault() method when click on element like <a> its stops the link to executed or on Form submit button click stop form to be submitted. HTML: <div id="div-element">         <a id="anchor-element" href="http://www.xyz.com" target="_blank">                xyz.com         </a> </div> CODE: $(“document”).ready(function(){ $(“#anchor-element”).click(function(event){   event.preventDefault(); }); }); event.stopPropagation() method: event.stopPropagation() method stops event handlers

This Article is TAGGED in , , . Read more