Your code throws below an error in the console: Uncaught TypeError: It is not possible to call the 'addEventListener' method from null which indicates that you need to first define your html element (anchor in this case) and then call methods on it.
What you do is the first call method (addEventListener in this case) and the html element definition (anchor in this case) later.
<html> <head></head> <body> <a id="id1">some crap</a><br> <a id="id2">crap</a> <script type="text/javascript"> function click_handler1() { alert("click_handler1"); } function click_handler2() { alert("click_handler2"); } document.getElementById("id1").addEventListener("click", click_handler1); document.getElementById("id2").addEventListener("click", click_handler2); </script> </body> </html>
source share