Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove All onclick Events for an Element

var links = document.body.querySelectorAll("p.sourcelinks a.individual_source_link");
for(var i=0;i<links.length;i++)
{
    links[i].onclick = null;
}

Is my current code, however it doesn't remove the onclick events. I have no idea what they will be since this is a greasemonkey script.

like image 533
Steven Avatar asked Feb 07 '11 07:02

Steven


1 Answers

Your code only deals with events added by element.onclick case. What about events added with addEventListener (for standards compliant browsers) and attachEvent (for IE)?

You need to use removeEventListener and detachEvent to remove events as well as setting .onclick to null. Then all your bases will be covered.

like image 115
GordonM Avatar answered Sep 17 '22 17:09

GordonM