I have a website where when you click on a button, the text inside the button changes to a random string from an array I made. That works fine, but when I try to make that button change the text inside multiple different spans, the function stops working altogether.
let exampleList = ['Shelf', 'Book', 'Political Idealogy', 'Laptop', 'Smartphone', 'Printer', 'Bicycle', 'Backpack'];
function newExample() {
let randomNumber = Math.floor(Math.random() * (exampleList.length));
document.getElementById('changeText').innerHTML = exampleList[randomNumber];
}
<h2>Find Your New
<button class="examples" onclick="newExample()"><span id="changeText">______</span></button>
</h2>
<p>
What you need is a <span id="changeText">______</span> or <button class="examples" onclick="newExample()"><span id="changeText">______</span></button>!
Now I know you can't use an ID more than once, but there's no other way that works. I've tried getElementbyClassName, querySelectorAll and none of them worked.
Just to clarify, I want what appears in the button to appear in every span that I set the class = 'changeText'.
I hope someone can point me to where I went wrong.