jQuery Event How to - Stop event default action








Question

We would like to know how to stop event default action.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  www .  ja va2 s  .  c  o m-->
    $('#list').on('click', '.status', function(e){
        e.preventDefault();
        console.log(this.href);
    });
});
</script>
</head>
<body>
  <ul id="list">
    <li><a class="status" href="1">link 1</a></li>
    <li><a class="status" href="2">link 2</a></li>
    <li><a class="status" href="3">link 3</a></li>
  </ul>
</body>
</html>

The code above is rendered as follows: