samedi 6 juin 2015

JS if else if else

Is there a way to run multiple if else statements from one event? For example, trying to run this, but it's only executing the first if else for the element with class "two" and not the second element which has class "three".

$(".hamburger-menu").click(function(){

if ($(".two").hasClass("two-rotate")){
$(".two").addClass("two-rotate-back").removeClass("two-rotate");
}

else {
$(".two").addClass("two-rotate").removeClass("two-rotate-back");
}

// This one won't execute
if ($(".three").hasClass("three-rotate")){
$(".three").addClass("three-rotate-back").removeClass("three-rotate");
}

else {
$(".three").addClass("three-rotate").removeClass("three-rotate-back");
}

I know the answer must be a simple one, but I've been searching for 30 minutes now and can't find the answer.

Aucun commentaire:

Enregistrer un commentaire