Umrete Kurvi Umrete Kurvi - 24 days ago 8
jQuery Question

Adding a If statement Inside If Function

Can somebody explain to me,how to add If inside If I mean something like that:



$(window).resize(function(){
if ($(window).width()<1000)
{
$('.search-trigger').on('click',function(){
if($('.search-overlay').hasClass('show'))
$('.search-overlay').removeClass('show');
}
else
{
$('.search-overlay').addClass('show');
}
});
}
});





If browser window is under 1000px ,turn on other search-menu style (full overlay search page), when click on search button. I'm using this code at the moment and got a error in console,which is:


Uncaught SyntaxError: missing )


after argument list.
Please if somebody can explain to me how to add If into If,to fix my search menu.THANKS !!

Answer
    var smallerThanThousand = false;
    $(window).resize(function(){
            if ($(window).width()<1000)
            {
                smallerThanThousand = true;
            }else{
                smallerThanThousand = false;
            }
    });
    $('.search-trigger').on('click',function(){
        If(smallerThanThousand === true){
            if($('.search-overlay').hasClass('show')){
                $('.search-overlay').removeClass('show');
            }
            else
            {
                $('.search-overlay').addClass('show');
            }
        }
    });
Comments