1479 posts The right tools with none of the gimmicks
  • Has referred 100+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 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

2336 posts
  • Has referred 200+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Helped several times protecting Envato Market against copyright violations
+5 more
CreativeMilk
says

if () {

} else if (){

}else

{

26 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+3 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

2336 posts
  • Has referred 200+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Helped several times protecting Envato Market against copyright violations
+5 more
CreativeMilk
says

You can use basic javascript if else ;)

426 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 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
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
vasilios
says

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

1479 posts The right tools with none of the gimmicks
  • Has referred 100+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 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
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 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