<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 functionalit开发者_如何学Cy for this button when we "click"
$("#mybutton").onclick(function(){
//$("#mybutton").removeattr("onClick","");
})
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.
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/
Use unbind
to remove event listeners.
$("#mybutton").click(function(){
$(this).unbind("click");
})
(also, $().click
, not onclick
)
You can use the jQuery unbind function if you want to remove the click event.
$('#mybutton').unbind('click');
精彩评论