How do you catch a click event with plain Javascript?

后端 未结 6 1608
挽巷
挽巷 2021-01-31 10:11

I know that when using jQuery you can do $(\'element\').click(); to catch the click event of an HTML element, but how do you do that with plain Javascript?

6条回答
  •  -上瘾入骨i
    2021-01-31 10:29

    document.getElementById('element').onclick = function(e){
      alert('click');
    }
    

    DEMO: http://jsfiddle.net/e9jZW/1/

提交回复
热议问题