I have html code like this:
<input type="text" name="search1" class="search" id="search_term" onkeyup="check_search(e,this.value,'searchkey');">
And i want to unbind this key event on the document ready.
I have html code like this:
<input type="text" name="search1" class="search" id="search_term" onkeyup="check_search(e,this.value,'searchkey');">
And i want to unbind this key event on the document ready.
document.getElementById('search_term').onkeyup = null;
Inline event handler attributes are assigned to the oneventname
property of the element, so just set it to null to detach the event listener.
If you want a JavaScript only solution
You can just set the event listener to null.
document.getElementById("search_term").onkeyup = null;
Refer to this answer for more details: https://stackoverflow.com/a/803984/3747743
If you use jQuery
You have to use the unbind
method.
An example:
var handler = function() {
alert( "The quick brown fox jumps over the lazy dog." );
};
$( "#foo" ).bind( "click", handler );
$( "#foo" ).unbind( "click", handler );
For more informations: http://api.jquery.com/unbind/