I know there are a lot of questions regarding the getElementsByClassName
not working, however I browsed through many and coudldnt find an answer for my situation.
Basically I have the following code:
<script>
var res = localStorage.getItem('img');
if(res == null){
const myList = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
res = myList[Math.floor(Math.random() * myList.length)];
localStorage.setItem('img', res);
}
console.log(res);
document.getElementsByClassName("emoji").innerHTML = res
And several spans with same class:
<span class="emoji" style="font-size: 40px !important;"></span>
The problem is that the "res" doesn't print anything in span.
The console log prints everything fine and LS stores the information perfectly .
I have tried with ID's:
document.getElementsById("emoji").innerHTML = res
And it works perfectly, however only with the first div (as it should i suppose).
What could I be doing wrong in this situation?
Maybe I am not able to see a very simple mistake in my code.