开发者

How can I remove an inline onclick attribute with a bookmarklet?

There is an annoying webs开发者_StackOverflowite 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?


Not mentioned yet:

$('#myId')[0].onclick = null; // remove the inline onclick() event


Untested, but...

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

I guess you have already tried to

$("selector").unbind("click");


In some circumstances setting onclick to null won't work, but this should always work:

document.getElementById("myId").setAttribute("onclick", "");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜