event.preventDefault() vs. return false (no jQuery)

The W3C Document Object Model Events Specification in 1.3.1. Event registration interfaces states that handleEvent in the EventListener has no return value: handleEvent This method is called whenever an event occurs of the type for which the EventListener interface was registered. […] No Return Value under 1.2.4. Event Cancelation the document also states that Cancelation … Read more

What’s the difference between event.stopPropagation and event.preventDefault?

stopPropagation prevents further propagation of the current event in the capturing and bubbling phases. preventDefault prevents the default action the browser makes on that event. Examples preventDefault $(“#but”).click(function (event) { event.preventDefault() }) $(“#foo”).click(function () { alert(“parent click event fired!”) }) <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <div id=”foo”> <button id=”but”>button</button> </div> stopPropagation $(“#but”).click(function (event) { event.stopPropagation() }) $(“#foo”).click(function () … Read more