Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unbind keyup event?

Tags:

javascript

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.

like image 423
JBNavadiya Avatar asked Jan 27 '26 17:01

JBNavadiya


2 Answers

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.

like image 158
Niet the Dark Absol Avatar answered Jan 30 '26 07:01

Niet the Dark Absol


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/

like image 40
Nicolas Henrard Avatar answered Jan 30 '26 06:01

Nicolas Henrard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!