Can I remove inline event handlers using jQuery?

前端 未结 5 2167
夕颜
夕颜 2020-12-10 04:17

I have some HTML with an onclick attribute. I want to override that attribute using jQuery. Is there any way to remove the click handler using jQuery? Using unb

5条回答
  •  佛祖请我去吃肉
    2020-12-10 04:58

    $("#theElement")[0].onclick = function() {
      whatever();
    };
    // -- or --
    $("#theElement")[0].onclick = null;
    

    It's not that jQuery would make the standard DOM functions and properties go away. ;-)

提交回复
热议问题