Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the Existing javascript function for the button

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

In the above Input tag i have to remove the entire "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","");
})
like image 422
Someone Avatar asked Apr 28 '26 02:04

Someone


2 Answers

If you need to remove the onclick attribute "on-demand" use

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

Have a second look at the selector. You need to query the ID, your snippet trys to select mybutton as ID, which infact is the name of the element.

like image 169
jAndy Avatar answered Apr 30 '26 18:04

jAndy


You cannot use unbind to remove an inline model onclick handler. unbind will only work with jQuery-bound event handlers. It can be done like this:

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's onclick property
$("#id_button")[0].onclick = null;

Demo: http://jsfiddle.net/ax52z/

like image 24
karim79 Avatar answered Apr 30 '26 16:04

karim79