Trying to select a div with "weather-info-temp" class and do something on click. But I get an error that "document.getElementsByClassName("weather-info-temp")" is not a function... What am I doing wrong?
document.getElementsByClassName("weather-info-temp").on("click", function() {
// code
});
getElementsByClassName returns an array (like object) of elements and on is a jquery function.
If you have jquery, use
$(".weather-info-temp").on("click", function(){
// do stuff on click
});
If not use
var eles = document.getElementsByClassName("weather-info-temp");
for(var i=eles.length; i--;) eles[i].addEventListener("click", function(){
// do stuff on click
}, false);
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