views:

42

answers:

4
<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","");
})
A: 

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

$('#mybutton').unbind('click');
Dan Diplo
that will not work with `onclick` inline event handlers
jAndy
Yep, I would go with the approach jAndy explained since unbind does not work in the same case with my app.
Dick Lampard
@jAndy - He hadn't added the HTML code to make it clear it was an inline event at the time I answered.
Dan Diplo
+1  A: 

Use unbind to remove event listeners.

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

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

digitalFresh
+3  A: 

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.

jAndy
Thanks Andy It Worked out for me
Someone
+2  A: 

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/

karim79