jQuery Event How to - Handle click event from jQuery handler and Javascript attribute








Question

We would like to know how to handle click event from jQuery handler and Javascript attribute.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.js'></script>
<script type='text/javascript'>
function specialFunction()<!--from   w  ww  .  j a va2  s  . c  o  m-->
{
        console.log('Bobs your mothers brother');
}
$(window).load(function(){

    $('#special').click(function () {
        specialFunction();
        return false;
    });

});
</script>
</head>
<body>
  <div class="someclass">
    <input id="special" type="submit" value="Post"
      onclick=specialFunction() />
  </div>
</body>
</html>

The code above is rendered as follows: