Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.getElementsByClassName("").innerHTML - not working [duplicate]

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;
    });
like image 737
Ali Salman Avatar asked Dec 19 '22 21:12

Ali Salman


1 Answers

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);
like image 196
Leo Avatar answered Dec 21 '22 09:12

Leo