Use e.preventDefault() to stop an event - Javascript DOM Event

Javascript examples for DOM Event:preventDefault

Description

Use e.preventDefault() to stop an event

Demo Code

ResultView the demo in separate window

<!doctype html>
<html lang="en">
   <head> 
      <title>html demo</title> 
   </head> 
   <body> 
      <a id="navlink" href="http://google.com">Click me</a> 
      <div id="Reveal">
         Not Clicked/*from w  w  w .  j  ava  2  s . com*/
      </div> 
      <script>
    document.getElementById('navlink').addEventListener("click" , function(e){
        e.preventDefault();
        document.getElementById('Reveal').innerHTML = "Clicked";
    },false);

      </script>  
   </body>
</html>

Related Tutorials