Javascript: Split And Variable Issues
In this code execution here: http://sandrayoon.com/UAI/www3/newpin.php I wrote a JS function that grabs the image source of the clicked icon and extracts the needed word into the '
Solution 1:
I think your problem may have more to do with q as a global.
var root='img/pins/';
function swapImg(ima){
//---extract pin----//
var nr = ima.getAttribute('src').split('/');
nr = nr[nr.length-1].split('.')[0];
var q = nr.substring(nr.length-1,nr.length);
if(q==1) {
nr = nr.split('1')[0];
ima.setAttribute('src',root+nr+'2.png');
} else if(q==2) {
nr = nr.split('2')[0];
ima.setAttribute('src',root+nr+'1.png');
}
//-----------------//
}
Post a Comment for "Javascript: Split And Variable Issues"