View Full Version : test if an image is appended to an element

07-08-2012, 04:00 AM
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.

07-08-2012, 04:19 AM
sounds like you should use a switch

07-08-2012, 04:54 AM
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.

07-08-2012, 05:22 AM
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.)

07-08-2012, 02:23 PM
I guess another way would be to use a jump table. You can have a look here (http://www.codingforums.com/showthread.php?t=236556) to see how the various methods were explained to me when I was trying to get my head around them