I have a div element with class name today in my html file and I am trying to print temperature on it, for that I have writen the following code but this is not printing anything on the div element, kindly help.
$http.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22islamabad%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys")
.success(function (response) {
var result = response.query;
var temp=result.results.channel.item.condition.temp;
var text=result.results.channel.item.condition.text;
var weather = $scope.weather = temp+" "+text;
document.getElementsByClassName("today").innerHTML = weather;
});
getElementsByClassName
has no definition for innerHTML
because getElementsByClassName
returns a NodeList object not an element. A NodeList
is essentially a collection of elements.
If you need to return a single element then use getElementById
and pass the id of the element. Or even better, since you're already using jQuery, you can do the following...
$('.today').html(weather);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With