I need help with assigning values from an array to elements selected by the querySelectorAll function. I am trying to write code that will change the text to different values in the array when the browser width is below 768px, but I'm facing some challenges.
var newButtons = document.querySelectorAll("#buttonsize button");
var sizesArray = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"];
for(var i = 0; i < sizesArray.length; i++) {
newButtons[i].textContent = sizesArray[i];
}
An error occurs which says:
Uncaught TypeError: Cannot set properties of undefined (setting 'textContent')
I have also tried newb.textContent
and using a forEach
function without success.