I have an element with event set, e.g.
<input type="text" id="txt" onkeyup="javascript: alert('keyup');" />
Now, I want to intercept this event and run some other script in addition to default one.
I wrote following code:
jQuery(document).ready(function(){
var old = $("#txt").keyup;
$("#txt")
.unbind('keyup')
.attr('onkeyup', '')
.each(function() { this.onkeyup = null; });
$("#txt").keyup(function(event){
alert("before old call");
//old.call($(this));
alert("after old call");
});
});
But it is not working as I expected. Anybody knows how to make this working?
Link to fiddle: http://jsfiddle.net/p5JeA/
What if the keyup event for the input is not inlined, but set using jQuery bind?
I want to override/extend the default behaviour, I do not want to change the base code.
Here’s a working fiddle: http://jsfiddle.net/mrchief/p5JeA/2/
jQuery was not included in the resources. Also, I commented out some parts as you don’t need them.