lundi 5 juin 2017

jQuery hasClass and if

I have a problem with jquery hasClass.

$(document).ready(function () {

var body = $('body'),
    leftPane = $('.pane-left');

leftPane.on('click', function () {

    body.removeClass('left-closed');
    body.addClass('left-open');
    $('.pane-left h2').fadeIn(600);

    setTimeout(function() {
        rightPane.fadeOut(0);
        $('.pane-left-wrap').fadeIn(100);
        $('.pane-left-wrap .secondary-nav li:first-child').fadeIn(100);
        $('.pane-left-wrap .secondary-nav li:nth-child(2)').fadeIn(600);
        $('.pane-left-wrap .secondary-nav li:nth-child(3)').fadeIn(1200);
        $('.pane-left-wrap .secondary-nav li:nth-child(4)').fadeIn(1800);
        $('.pane-left-wrap .secondary-nav li:nth-child(5)').fadeIn(2400);
    }, 600);

});

if(body.hasClass('left-open')) {

    leftPane.on('click', function () {

        body.removeClass('left-open');
        body.addClass('left-closed');
        $('.pane-left h2').fadeOut(600);

    });

}

});

I click pane-left and left-open is added to my body tag. Then i click again but the code inside my if() is unreachable. Why is that?

Aucun commentaire:

Enregistrer un commentaire