How can I remove an inline onclick attribute with

2020-02-14 10:47发布

There is an annoying website out there that foils attempts to "open in new tab" by using <div onclick=> instead of <a href=>. I've written a bookmarklet, using jQuery, that creates a wrapper <a> tag and inserts it within the <div> around its content.

How can I remove the original onclick handler?

2条回答
够拽才男人
2楼-- · 2020-02-14 10:57

Untested, but...

$("selector").removeAttr("onclick");

I guess you have already tried to

$("selector").unbind("click");
查看更多
迷人小祖宗
3楼-- · 2020-02-14 11:08

Not mentioned yet:

$('#myId')[0].onclick = null; // remove the inline onclick() event
查看更多
登录 后发表回答