Ad

Jquery Multiple Actions On Condition

- 1 answer

To configure a burger navigation, I'm trying to perform 2 changes from one condition. I'm getting the following error :

SyntaxError: missing : in conditional expression

My code is as follows :

    $(".burger").on("click", function() {
    "20px" == $(".main-navigation").css("left") ? $(".navbarWrap").css("z-index", "-1"), $(".main-navigation").animate({
        left: "100%"
    }, 200) : $(".navbarWrap").css("z-index", "1"), $(".main-navigation").animate({
        left: "20px"
    }, 200)
})

Any idea where my error is ? Thanks

Ad

Answer

$(".burger").on("click", function() {
"20px" == $(".main-navigation").css("left") ? ($(".navbarWrap").css("z-index", "-1"), $(".main-navigation").animate({
    left: "100%"
}, 200)) : ($(".navbarWrap").css("z-index", "1"), $(".main-navigation").animate({
    left: "20px"
}, 200))
});

You need to wrap the if else outputs in ()

Ad
source: stackoverflow.com
Ad