Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "onclick" with JQuery?

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?

like image 728
Steven Avatar asked Nov 06 '09 14:11

Steven


People also ask

How to remove onclick event jQuery?

Using unbind() method: It is an inbuilt method in jQuery which is used to remove any selected event handlers.

How do I remove Onclick from an element?

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.

How remove Onclick react?

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.

Which of the following method can be used to remove event handlers?

The off() method is most often used to remove event handlers attached with the on() method.


1 Answers

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>
like image 136
glmxndr Avatar answered Sep 20 '22 19:09

glmxndr