How do I bind a click to an anchor without a framework (javascript)

前端 未结 6 596
难免孤独
难免孤独 2020-12-06 05:23

I know this is easily done in jQuery or any other framework, but that\'s not really the point. How do I go about \'properly\' binding a click event in pure javascript? I kno

6条回答
  •  执笔经年
    2020-12-06 05:27

    Give it an ID and you should be able to do:

    document.getElementById("the id").onclick = function{ ... }
    

提交回复
热议问题