sledgeweight
sledgeweight

Reputation: 8095

Issue with unbind click with off

$('.filter-tab').on('click', function(){
    var $correspondingOverlay = $(this).next().next();
    $correspondingOverlay.fadeIn();
    if($('#one').is(':visible')) {
        $('#sort h2').off('click');
    }
    if($('#two').is(':visible')) {
        $('#filter h2').off('click');
    }
});

$('.close').on('click', function () {
    $('.filter-results').fadeOut();
    $('#filter h2, #sort h2').on('click');
});

The off() part doesnt take of the click and still allows correpsoding overlay to fade in. Any ideas where I'm going wrong here?

Upvotes: 0

Views: 35

Answers (2)

Anoop Joshi P
Anoop Joshi P

Reputation: 25527

try

 $('body').off('click','#filter h2',function(){});

Upvotes: 0

KoalaBear
KoalaBear

Reputation: 2948

The off should have the same selector as the on.

Therefore this should work:

$('.filter-tab').off('click');

Else you must have multiple different .on's with less generic selector.

Upvotes: 1

Related Questions