0

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 !!

4
  • Fix your indentation and trace your brackets. There is a syntax error in your code. Commented Nov 11, 2016 at 19:34
  • 1
    FYI - you need to unbind the click handler before assigning a new one. This will add a new handler every resize event and that fires pretty often when resizing a window. Nothing good will come of that. Commented Nov 11, 2016 at 19:34
  • 2
    The second if needs an open {. I want to echo @asawyer comment. You don't want to continuously add click handlers (thousands of them) when your window resizes. Commented Nov 11, 2016 at 19:37
  • Well thanks! That was for the error,but function isnt working ;/ Commented Nov 11, 2016 at 19:48

1 Answer 1

1
    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');
            }
        }
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.