I need help with Show the Local Weather icons

I am trying to add icons to my project but i don’t have idea where i have made the mistake. Why my code doesn’t work?

var iconCode = result.weather[0].icon;
var iconUrl = “http://openweathermap.org/img/w/” + iconCode + “.png”;
$("#myIcon").html("");

Thank you for answer. I used iQuery to add icons to the project. All my code:

You need you url to attach to href attribute of your $("#myIcon") element i suppose? If so:
$("#myIcon").attr(“href”,iconUrl);

or if you use vanilla js:
document.getElementById(“myIcon”).href = iconUrl;

About a icon thingy:
$("#myIcon").prepend("");
This being said, you can use html(), but that will replace everything in $("#myIcon") element. Prepend just adds it before rest of elements in $("#myIcon") element. .

1 Like

$("#myIcon").attr( “src”,json.weather[0].icon);

Yes if it already has src attribute. If it doesn’t, then $("#myIcon").prepend("");

Thank you your help.