Javascript examples for DOM Event:preventDefault
Block a link from working using preventDefault()
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <a id="link" onclick="test()" href="http://www.example.com">Text</a> <script type="text/javascript"> function test() {/*from w ww .j a v a 2s .c o m*/ return "texttoblock" === prompt("Some question / text").toLowerCase() ? (window.event.preventDefault(), console.log("text"), !1) : !0 } </script> </body> </html>