-4

so basically I am trying to create a ie9 specific if statement that basically says if the menu collapsed = true move 3 classes from the left and the opposite for if it is false... can't seem to get this statement working though can someone help ? this is what i have so far ...

var ms_ie = false;
var ua = window.navigator.userAgent;
var old_ie = ua.indexOf('MSIE ');
var new_ie = ua.indexOf('Trident/');

if ((old_ie > -1) || (new_ie > -1)) {
    ms_ie = true;
}
if ( ms_ie ) {        
    if $('#menu').multilevelpushmenu({Collapsed: false}) {
        $( ".navbtn, .submenu-ctn, .logo-title" ).animate({
            left: "+=310",
        }, 500);             
        else {
            $( ".navbtn, .submenu-ctn, .logo-title" ).animate({
                left: "-=310",
            }, 500);
        }
    }
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

2 Answers2

1

This has nothing to do with your "if, if, if statement"; it's just one of the if statements that's wrong:

if $('#menu').multilevelpushmenu({Collapsed: false}) {

Parentheses!!!

if ($('#menu').multilevelpushmenu({Collapsed: false})) {

When you're developing for the web, try to use your browser's development tools. They will tell you all about syntax errors.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

As others have pointed out in comments, your code is not syntactically valid. You need one additional closing tag as below.

You have not included the relevant HTML & CSS that might go along with this, so it is hard to judge precisely what effect you are going for.

var ms_ie = false;
var ua = window.navigator.userAgent;
var old_ie = ua.indexOf('MSIE ');
var new_ie = ua.indexOf('Trident/');


if ((old_ie > -1) || (new_ie > -1)) {
    ms_ie = true;
}
if ( ms_ie ) { // CT1

    if ($('#menu').multilevelpushmenu({Collapsed: false})) { // Parentheses around condition.
        $( ".navbtn, .submenu-ctn, .logo-title" ).animate({
            left: "+=310",
        }, 500); 

        else {
            $( ".navbtn, .submenu-ctn, .logo-title" ).animate({
                left: "-=310",
            }, 500);
        }
    } // close CT 1 - last one included in example.
} // Needs one more closing tag :)

Check out this answer to the issue of detecting IE with Javascript. Might make for a cleaner and more readable version of code. You can get a numeric IE version from that function.

Community
  • 1
  • 1
sqsinger
  • 500
  • 1
  • 3
  • 13
  • i just figured out the extra tag at the end but looking at the answer now thank you for visually explaining – tryingmybest Jun 25 '15 at 17:39
  • my debug tells me that it is expecting a ( after the if bit in the if $('menu') – tryingmybest Jun 25 '15 at 17:40
  • Correct - just updated in my answer. As @LightnessRacesinOrbit points out, conditions within each `if` statement must be surrounded by parentheses. – sqsinger Jun 25 '15 at 17:42
  • yes i saw that and appreciate it , It is now saying that i need a : after the 500 , i don't think the examples of timers i saw with animate had that though – tryingmybest Jun 25 '15 at 17:45
  • _"You need one additional closing tag as below."_ That's actually not true. His indentation is misleading. – Lightness Races in Orbit Jun 25 '15 at 17:54
  • now i am totally confused , lightness you sound like you know what you are talking about but i am going backwards here not forward – tryingmybest Jun 25 '15 at 17:55
  • @tryingmybest: If you feel frustrated, it's time to take a break. Go have some food, take some deep breaths. Then come back, read everything that's been said (_everything!_) and think it through logically. – Lightness Races in Orbit Jun 25 '15 at 17:56
  • No not frustrated , just confused lol here is what it is saying in debug if ($('#menu').multilevelpushmenu({Collapsed: false})) { $( ".navbtn, .submenu-ctn, .logo-title" ).animate({ left: "+=310", }IDENTFIER EXPECTED HERE, 500); else { – tryingmybest Jun 25 '15 at 17:57