views:

185

answers:

4

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?

A: 

Untested, but...

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

I guess you have already tried to

$("selector").unbind("click");
Victor
Didn't work for me.
Diodeus
Neither seemed to work. I also tried`$("selector").attr("onclick",function(){})`
Eric
The first example here worked for me. $(document).ready(function(){ $('div').removeAttr('onclick'); });
AdmSteck
A: 

Hi,

I think you would have to call all posible detach methods:

native Javascript:

removeEventListener()  //  detachEvent()

jQuery:

.unbind()  //  .die()  //  .undelegate()

DOM:

.removeAttr('onclick'

Kind Regards

--Andy

jAndy
A: 

Not mentioned yet:

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

In the end, the simplest solution was to delete the div entirely, thus negating any event handlers.

Eric