Can I remove inline event handlers using jQuery?

前端 未结 5 2160
夕颜
夕颜 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 05:12

    As quoted in http://api.jquery.com/prop/ Removing an inline onclick event handler using .removeAttr() doesn't achieve the desired effect in Internet Explorer 8, 9 and 11. To avoid potential problems, use .prop() instead.

    So this can be done as

    $(function() {
        $('a').prop('onclick', false);
    });
    

提交回复
热议问题