samedi 18 mars 2017

Jquery If integer equals on click event

Hello guys I am trying to achieve something with jquery but i cant get it to work. I want the button .btn-toggler to fire event if the value of my variable $da equals -150. The value of $da is the margin-left value of another element's class. If i work it out on developer tools console log, my parseInt function returns -150 but $da is undefined!

Here is my code:

$(document).ready(function() {
var $da = 0;
$('.btn-toggler').click(function() {
    $da = parseInt($(".sidemenu").css('marginLeft'));
    if ($da == -150) {
        $('.sidemenu').addClass('active-nav');
        $('.body').addClass('bodyactivenav');
    }
    else {
        $('.sidemenu').removeClass('active-nav');
        $('.body').removeClass('bodyactivenav');
    }
});

});

Aucun commentaire:

Enregistrer un commentaire