0

I'm having a problem getting the condition in this if statement to work, i've tried getElementById & src.indexOf but I am still very new to this. I am trying to replace the blank/ball image with the x/pikachu image only if the blank image is currently showing, so if there was one of the other images there it wouldn't replace it. It doesn't seem to recognize the condition I have in there as true, any idea why? i've also tried:document.getElementById(bn).src=blank & document.images[bn].src==blank & document.pokemon.bn.src==blank looking for a way to verify if the current source of the image is the var blank. thank you

 var x = "pikachu.jpg";
 var o = "Meowth.jpg";
 var blank = "ball.jpg";             

 function b1Move(imageName){
 temp2=imageName;
 if(document.pokemon[temp2].src==blank)  
 document.pokemon[temp2].src=x;
 cMove();
 }

and the html for the images looks like this:

 <a href="javascript:b1Move('b1')"><img src="ball.jpg" height=150 width=150 name=b1         
 id =b1  > </a>

2 Answers 2

2

The src property gives the fully resolved URL. You probably want to use the src attribute, which stays the same:

if( document.pokemon[temp2].getAttribute("src") == blank)
    document.pokemon[temp2].setAttribute("src",x);
Sign up to request clarification or add additional context in comments.

Comments

0

you should try

if(document.pokemon[temp2].src.indexOf(blank) != -1)

since src is the full url.. then you can check it it contains your image name

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.