jquery .off(): how to remove a certain click handler only?

前端 未结 4 1098
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 04:04

I\'ve an element with two handler bound to it:



$(\'.pippo\').on(\'click\', function () {
             


        
4条回答
  •  不知归路
    2020-12-30 04:59

    One easier alternative with jQuery is to define a namespace for your click events:

    $('.pippo').on('click.first', ...);
    $('.pluto').on('click.second', ...);
    
    // Remove only the pippo listener
    $('.pippo').off('click.first');
    

    Note that your classes pippo and pluto refer to the same element so using one or the other will not change anything.

    https://jsfiddle.net/6hm00xxv/2/

提交回复
热议问题