Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    test if an image is appended to an element

    I need a way to be able to test if Image "X" is currently appended to Div "A". I have several images that can only be displayed one at a time, and when a button is clicked, it should redirect to different pages depending on what image is currently being displayed. I assume there's a far more efficient way to do this that having a ton of boolean variables that change in accordance to the image appending, but I don't know what it is. Help appreciated.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    sounds like you should use a switch

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh yes, that's what they'rr called. I wasn't aware JS had them. I haven't really been learning JS so much as just picking up what parts of it I need when I need them. So, time to look up switches. Thx.

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, correct me if I'm wrong, but it from what I understand, switches are really no different from if...else statements (except possibly being somewhat more efficient). That's not really what I was expecting; I was thinking a switch would be something like an array of booleans where only one boolean could be true at a time, and when I set one boolean to be true, the others would set to false without me having to explicitely code it. But as it seems, with a switch I will still need to explicitely set one boolean to true and the rest to false for every case, and that's a lot of lines of code...

    On the other hand, if you're talking about using a switch to directly test whether an image is appended or not, instead of using booleans to represent their status, what I need to know is the exact syntax I would need to supply as cases (or as arguments to if...else statements since it could also be done that way.)

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    I guess another way would be to use a jump table. You can have a look here to see how the various methods were explained to me when I was trying to get my head around them


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •