var isEven = function(someNumber) { return someNumber % 2 === 0; }; if (!isEven(count)) { $(this).toggleClass('my3d'); $(".main-menu a").removeAttr("class"); $(".main-cube").animate({top: "0%"}, 1000); $(".cube").css({width: "95vw", height: "45vh", transform: "rotate3d(0,1,0,0deg)", left: "0"}); $(".side").addClass("landing-loft").css({width: "80vw", height: "100vh"}); } // on even clicks do this else if (isEven(count) === true) { $(".main-menu a").attr("class"); $(".main-cube").css("top", "10%"); $(".cube").css({width: "600px", height: "600px"}); $(".side").removeClass("landing-loft").css({width: "600px", height: "600px"}); } }); 

The upper part is working, lower in principle, too, but with the help of $(".main-menu a").attr("class"); I can’t go back to return the class attribute so the cube rotates. How can I get it back?

    1 answer 1

    For an odd click, we will save the values ​​of the class attributes in data for each element from $(".main-menu a") , and for an even click, we will restore it.

     var isEven = function(someNumber) { return someNumber % 2 === 0; }; if (!isEven(count)) { $(this).toggleClass('my3d'); $(".main-menu a").each(function() { $(this).data("storedclass", $(this).attr("class")); $(this).removeAttr("class"); }); $(".main-cube").animate({top: "0%"}, 1000); $(".cube").css({width: "95vw", height: "45vh", transform: "rotate3d(0,1,0,0deg)", left: "0"}); $(".side").addClass("landing-loft").css({width: "80vw", height: "100vh"}); } else { // on even clicks do this $(".main-menu a").each(function() { $(this).attr("class", $(this).data("storedclass")); }); $(".main-cube").css("top", "10%"); $(".cube").css({width: "600px", height: "600px"}); $(".side").removeClass("landing-loft").css({width: "600px", height: "600px"}); } }); 
    • Taki earned. Thank!! - Vladimir Abramovich