jQuery Event How to - Put click event Handler to a function








Question

We would like to know how to put click event Handler to a function.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  w w  w.  ja v  a2s  .c  o  m-->
    $(document).ready(function () {
         function count_send_at(event) {
    
            console.log('bye');
         }
         $('#count_send_at_btn').click(count_send_at);
    });
});
</script>
</head>
<body>
  <a href="#" id="count_send_at_btn">HELLO</a>
</body>
</html>

The code above is rendered as follows: