1475 posts The right tools with none of the gimmicks
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Has been a member for 4-5 years
  • Referred between 50 and 99 users
  • Bought between 10 and 49 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • United States
+1 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

2317 posts
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
+1 more
CreativeMilk says

if () {

} else if (){

}else

{

26 posts
  • Bought between 100 and 499 items
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
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

2317 posts
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
+1 more
CreativeMilk says

You can use basic javascript if else ;)

426 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
  • United States
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
  • United States
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 5-6 years
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
+4 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
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
  • United States
vasilios says

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

1475 posts The right tools with none of the gimmicks
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Has been a member for 4-5 years
  • Referred between 50 and 99 users
  • Bought between 10 and 49 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • United States
+1 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
  • United States
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 5-6 years
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
+4 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
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
  • United States
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