How to remove existing javascript function for button

<input name="mybutton" type="button" class="agh" id="id_button" value="Dim" onClick="resetDims();">

In the above input tag, I have to delete everything "Onclick = myfunction ();" and its function for the input tag and write my functionality for this button when we "click"

$("#mybutton").onclick(function(){
  //$("#mybutton").removeattr("onClick","");
})
+3
source share
4 answers

If you need to remove the onclickon-demand attribute , use

$('#id_button').removeAttr('onclick').click(function(){
});

Take a second look at the selector. You need to request IDyour fragment is trying to select mybuttonas an identifier, which is the name of the element.

+3
source

unbind, onclick inline model. unbind jQuery. :

document.getElementById("id_button").onclick = null;

// you can still get the element using the jQuery shorthand though
// the point is to get at the DOM element onclick property
$("#id_button")[0].onclick = null;

: http://jsfiddle.net/ax52z/

+2

Use unbindto remove event listeners.

$("#mybutton").click(function(){
  $(this).unbind("click");
})

(also $().click,, not onclick)

+1
source

You can use the jQuery unbind function if you want to remove the click event.

$('#mybutton').unbind('click');
0
source

Source: https://habr.com/ru/post/1758218/


All Articles