1479 posts The right tools with none of the gimmicks
  • Affiliate Level 4
  • Author Level 7
  • Beta Tester
  • Collector Level 2
+7 more
PixelBin
says

I’m trying to target only one if statement (either this or that), and else if would work in this case but I’m sure if Javascript has an ‘else if’?

Kinda confusing but I’m “in the learning process”... :P

2337 posts
  • Affiliate Level 5
  • Author Level 6
  • Collector Level 2
  • Trendsetter
+7 more
CreativeMilk
says

if () {

} else if (){

}else

{

26 posts
  • 7 Years of Membership
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 4
+4 more
webgurus
says

Hey, There is “else if” function in javascript example of it’s use here

If you want an alternative there is a plugin for jQuery

2337 posts
  • Affiliate Level 5
  • Author Level 6
  • Collector Level 2
  • Trendsetter
+7 more
CreativeMilk
says

You can use basic javascript if else ;)

426 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Author Level 4
  • Beta Tester
+4 more
vasilios
says

The “else if” statement in JS is like writing nested if/else statements but the else statements don’t have brackets making it on one line. :)

if (...) {

} else {
     if (...) {

     } else {
          if (...) {

          }
     }
}
2541 posts
  • Affiliate Level 2
  • Author Level 2
  • Collector Level 3
  • United States
+9 more
CreatingDrew
says
Hey, There is “else if” function in javascript example of it’s use here If you want an alternative there is a plugin for jQuery
Wow, I can’t believe someone made a plugin for basic conditional statements, that’s crazy.

@Vasilios – I think your example is more complicated than it needs to be :)

basic else if:

var myNum = 10;
if (myNum > 10) {
   alert('Greater than 10.');
} 
else if (myNum < 2) {
   alert('Less than 2.');
}
else {
    alert(myNum);
}

switch statement

Or use a switch statement (as long as you understand how they work, certain cases can fall through to another if you aren’t careful):


switch(someVariable) {
   case 1:
      block of code;
      break;
   case 2:
      block of code;
      break;
   default:
      block of code;
}

426 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Author Level 4
  • Beta Tester
+4 more
vasilios
says

^ Yeah. XD My book examples it better than I do.

1479 posts The right tools with none of the gimmicks
  • Affiliate Level 4
  • Author Level 7
  • Beta Tester
  • Collector Level 2
+7 more
PixelBin
says
The “else if” statement in JS is like writing nested if/else statements but the else statements don’t have brackets making it on one line. :)
if (...) {

} else {
     if (...) {

     } else {
          if (...) {

          }
     }
}
GET ON AIM , I need your help!!! :)

...puh-lease :)

2541 posts
  • Affiliate Level 2
  • Author Level 2
  • Collector Level 3
  • United States
+9 more
CreatingDrew
says
The “else if” statement in JS is like writing nested if/else statements but the else statements don’t have brackets making it on one line. :)
if (...) {

} else {
     if (...) {

     } else {
          if (...) {

          }
     }
}
GET ON AIM , I need your help!!! :)

...puh-lease :)

Like I said, you really don’t need to write it that way.
426 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Author Level 4
  • Beta Tester
+4 more
vasilios
says
The “else if” statement in JS is like writing nested if/else statements but the else statements don’t have brackets making it on one line. :)
if (...) {

} else {
     if (...) {

     } else {
          if (...) {

          }
     }
}
GET ON AIM , I need your help!!! :)

...puh-lease :)

Like I said, you really don’t need to write it that way.

I was just writing that showing how it would normally be written without else if. :)

by
by
by
by
by
by