开发者

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

开发者 https://www.devze.com 2022-12-25 15:27 出处:网络
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, usi

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

精彩评论

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