PHP code:
<a id="a$id" onclick="check($id,1)" href="javascript:void(0)" class="black">Qualify</a>
I want to remove the onclick="check($id,1)
so the link cannot be clicked or "check($id,1)
won't be fired. How can I do it with JQuery?
Using unbind() method: It is an inbuilt method in jQuery which is used to remove any selected event handlers.
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.
Remove stand-alone element onclick in ReactAttach an event handler to the onClick event of the element. In the event handler, negate the value of the visibility state to remove the element from the DOM.
The off() method is most often used to remove event handlers attached with the on() method.
Old Way (pre-1.7):
$("...").attr("onclick", "").unbind("click");
New Way (1.7+):
$("...").prop("onclick", null).off("click");
(Replace ... with the selector you need.)
// use the "[attr=value]" syntax to avoid syntax errors with special characters (like "$") $('[id="a$id"]').prop('onclick',null).off('click');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <a id="a$id" onclick="alert('get rid of this')" href="javascript:void(0)" class="black">Qualify</a>
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