Javascript examples for DOM:Event
The defaultPrevented event property checks if the preventDefault() method was called for the event.
A Boolean, telling if the preventDefault() method was called for the event.
The following code shows how to Prevent a link from opening the URL, and check if preventDefault() was called:
<!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()/* ww w . j av a 2 s . c om*/ console.log("Was preventDefault() called: " + event.defaultPrevented); }); </script> </body> </html>