Schnulli Schnulli - 1 year ago 66
jQuery Question

Remove JQuery 1.11.1 events (for a Userscript)

I am using a web application and I want to change its behaviour for myself via Tampermonkey. The problem is, that the middle mouse click for opening a new tab doesn't work because the click event is overridden. I have no chance to change the application on server side! So the easiest would be to remove the event.

It is removing the event, when I am removing the event withing the Chrome Developer Tools manually via the remove button:

The app is using jquery-1.11.1.min.js so I want to remove those events via JQuery.

HTML Snippet where the event is attached (also see the screenshot):

I have tried to remove the onclick part in the html and I removed the event via following javascript: (first of all in the Developer Console of Chrome):


But without success. Only removing it via the remove button in the Event Listernes Tab working fine (without any other step).
Am I missing some events when I am doing that via javascript?

Answer Source

You can try this way


.off() is reccomended and available from JQuery 1.7 and above.

If your document is valid (no duplicated IDs), you should remove "a" tag from selector, because it can cause really bad performance.