Computer >> Computer tutorials >  >> Programming >> Javascript

How to handle bind an event using JavaScript?


To handle an event using JavaScript, use click, for mouse click event on any element.

Example

You can try to run the following code to learn how to handle bind an event using JavaScript:

Live Demo

<!DOCTYPE html>
<html>
<body>
<a href="#" id="anchor">Click me</a>

<script>
  document.getElementById('anchor').addEventListener('click', function() {
    alert('You have clicked the link');
  });
</script>

</body>
</html>