I have an anchor like this
<a href='#' onclick='return showform(this)'>click me</a>
But I want to be able to override the onclick function, how to do this in jquery?
because it seems when I add
$('a').click( function() { alert('hi there!'); } );
the new click handler is not overriding the old one
Use the off() method to override jQuery event handlers. This method is used to remove an event handler. The on() method is used to attach one or more event handler.
You simply get a reference to the function "getEditor" and assign it another function. getEditor:function(){ // new function will override the existing reference that getEditor already has. } Show activity on this post. You must get object where getEditor function stored, and use reference to change it.
jQuery unbind() MethodUse the off() method instead. The unbind() method removes event handlers from selected elements. This method can remove all or selected event handlers, or stop specified functions from running when the event occurs. This method can also unbind event handlers using an event object.
In your case the onCick event is overriding the jQuery one. What you might be able to do is:
$('a').unbind('click').click(function(){
alert('why hello there children.');
})
But I believe this would have to be included after the
<a href='#' onclick='return showform(this)'>click me</a>
That said, you should really not be using onClicks anyway... it makes the code really hard to maintain and change (as you have found out).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With