jQuery HTML Element How to - Skip change location when clicking on a link








Question

We would like to know how to skip change location when clicking on a link.

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(){<!--  ww  w  .  j a  v  a 2  s.  c om-->
    $('a').click(function() { 
        $(this).css('background', 'gray');
        return false;
    });
});
</script>
</head>
<body>
  <a href="no-js-link.html">Click action</a>
</body>
</html>

The code above is rendered as follows: