Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you unbind only some events?

I have a few things like this...

$('body').on('keyup', function(e){if(e.which === 32){//do stuff}})

I need to disable some of these events at times but not all of them.

$('body').off('keyup') just turns them all off.

like image 878
fancy Avatar asked Dec 01 '25 05:12

fancy


2 Answers

Namespace them...

$('body').on('keyup.some_name', function(e){if(e.which === 32){//do stuff}})

$('body').off('keyup.some_name')
var onKeyUp = function(e){if(e.which === 32){//do stuff}}

$('body').on('keyup', onKeyUp);

// later...

$('body').off('keyup', onKeyUp);
like image 21
Dmitry Nogin Avatar answered Dec 03 '25 18:12

Dmitry Nogin



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!