How do you override inline onclick event?

前端 未结 4 1853
暗喜
暗喜 2020-12-02 09:07

This seems deceptively simple.

How do you override the onclick event in the following HTML using JavaScript?



        
4条回答
  •  粉色の甜心
    2020-12-02 09:49

    Try this:

    // Setting the DOM element's onclick to null removes 
    // the inline click handler
    $("#sample")[0].onclick = null;
    $("#sample").click(function() { alert("done") });
    

提交回复
热议问题