How to handle bind an event using JavaScript?

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 19-Dec-2017 17:06:22
Advertisements