variables - Global boolean not working within function - Javascript -
<script> var xturn = true; function changeimage() { element=document.getelementbyid('myimage') if (element.src.match("/wp-content/uploads/2013/07/squaree.png") && xturn) { xturn = false; element.src="/wp-content/uploads/2013/07/xx.png"; } else if (element.src.match("/wp-content/uploads/2013/07/squaree.png") && xturn==false); { xturn = true; element.src="/wp-content/uploads/2013/07/circ.png"; } } </script> <img id="myimage" onclick="changeimage()" src="/wp-content/uploads/2013/07/squaree.png" width="90" height="90">
for reason xturn doesn't seem work within function. referencing if incorrectly? in wordpress, way. have checked make sure image changes without xturn being used.
i think using match wrong , element.src give complete url with
http://domain....
try
element.src.indexof("squaree") != -1
Comments
Post a Comment