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.


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

Live Demo

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

  document.getElementById('anchor').addEventListener('click', function() {
    alert('You have clicked the link');

Published on 19-Dec-2017 12:36:22