This is a weird question. We have some production links down on our intranet. Some rouge javascript is returning a "false" on all links on our intranet homepage.
We don't have access to the source to re-build the control and fix this javascript.
So as a temporary band-aid I want to move all the "onClick" events on the links using jquery
The links right now are like this:
<a href="https://www.mysite.com/" onclick="AddHit('Header: mysite.com', 'http://www.mysite.com'); return false;" title="Mysite Home">www.Mysite.com</a>
I want to write some jquery to get ride of the "onclick='AddHit..." code.
To remove an element from the DOM onclick in JavaScript: Select the DOM element with a method like getElementById() . Add a click event listener to the element. Call the remove() method on the element in the event handler.
Answer: Use the jQuery off() Method You can simply use the jQuery off() method to remove the event handlers that were attached with on() .
We set an event handler to the onClick event of the button, so when the button is clicked, the handler function will be called. In the handler function, we use the setState function for the visibility state to update the state. const removeElement = () => { setVisible((prev) => ! prev); };
You can try this:
$("a").removeAttr("onclick");
Edit Updating answer based on comments and jquery Docs:
Note: Removing an inline onclick event handler using .removeAttr() doesn't achieve the desired effect in Internet Explorer 6, 7, or 8. To avoid potential problems, use .prop() instead
Best way to do this:
$("a").prop("onclick", null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With