Javascript examples for DOM:Event
The preventDefault() method cancels the cancelable event.
To stop propagation of an event through the DOM, use the stopPropagation() method.
None
No return value
The following code shows how to Prevent a link from opening the URL:
<!DOCTYPE html> <html> <body> <a id="myAnchor" href="http://java2s.com">Visit java2s.com</a> <script> document.getElementById("myAnchor").addEventListener("click", function(event){ event.preventDefault()/*w w w . j av a 2 s . co m*/ console.log("Was preventDefault() called: " + event.defaultPrevented); }); </script> </body> </html>