hello guys, I’m kind of stuck and need your help, my issue is with jquery attr method. I’m trying to change icon depending on icon value I get from weather api…( I do get a proper value) here is a function which should change img src according to icon argument:
function changeIcon(icon){
var iconClear_Sky = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconClear_Sky_Night = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconRain = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconSnow = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconSleet = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconWind = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconFog = “https://res.cloudinary.com/dviy2q8nb/image”;
var iconCloudy = “https://res.cloudinary.com/dviy2q8nb/image”;
console.log(“func: " + icon);
switch(icon){
case “clear-day”:
$(”#icon").attr(“src”,iconClear_Sky);
break;
case “clear-night”:
$(“#icon”).attr(“src”,iconClear_Sky_Night);
break;
case “rain”:
$(“#icon”).attr(“src”,iconRain)
break;
case “snow”:
$(“#icon”).attr(“src”,iconSnow);
break;
case “sleet”:
$(“#icon”).attr(“src”,iconSleet);
break;
case “wind”:
$(“#icon”).attr(“src”,iconWind);
break;
case “fog”:
$(“#icon”).attr(“src”,iconFog);
break;
case “cloudy”:
case “partly-cloudy-day”:
case “partly-cloudy-night”:
$(“#icon”).attr(‘src’,iconCloudy);
console.log(“got here, src: " + iconCloudy);
break;
default:
$(”#icon").attr(“src”,iconClear_Sky_Night);
break;
}
}
Links are simplified I provide proper links in my app, values are set properly… switch also works and I get to proper case $(“#icon”).attr('src", NewLink) also doesn’t returns any error but icon isn’t changed.
Link to my codepen
https://codepen.io/gmdivani/pen/weYBam?editors=1001
Edit!.. Fixed issue with changing id selector to img selector… but if anyone can explain why id selector didn’t worked I will be really thankful (obviously I checked id name dozen times and it was set correctly).
, it will be way better.