javascript - if statement with img.src -


the problem: whenever, if have single '=' variable show , fine.. ignores if statement. if double '=='.. variable doesnt show up, , goes else state. lemme know if u see wrong.

var pic1 = document.getelementbyid('team1pic').src; var win1 = document.getelementbyid('wins').innerhtml; if (pic1 == 'pens.jpg') {     document.getelementbyid('wins').innerhtml = pittwins; } else {     document.getelementbyid('wins').innerhtml = 'no'; } 

here html go along have

<a class="dock-item" id="pens" href="#" onclick="document.getelementbyid('team1pic').src='pens.jpg'"><span>pittsburgh penguins</span><img src="pens.jpg" alt="pittsburgh penguins" /></a>`  

and

<th width="35%" ><img src="" / id='team1pic'></th> 

i nice see html attached to.

the reason single = works == doesn't points conclusion not equal. reason shows = because assignment evaluates true. case assign variable "truthy", meaning value evaluate true in js. in javascript 0, false, null & undefined evaluate true.

you might want alert(pic1) see in there, or if using firefox or chrome can use javascript debugger tools.


Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -