Use forEach
, for ... of
, or an usual for
loop instead. With these you can access every element in the NodeList
. Because NodeList
is not a normal Array
, using for...in
on it will give you other properties of the NodeList
object, like "item"
, "keys"
, and the problematic one in your case, .length
. Indeed, in "strict mode", you can't set properties on number primitives.
Using forEach
that would give:
const copyright = document.querySelectorAll('.copyright');
copyright.forEach(elem => {
elem.textContent = new Date().getFullYear();
})
Using for...of
:
const copyright = document.querySelectorAll('.copyright');
for(const elem of copyright) {
elem.textContent = new Date().getFullYear();
}
And using the usual for
loop:
const copyright = document.querySelectorAll('.copyright');
for(let i = 0; i < copyright.length; i++) {
copyright[i].textContent = new Date().getFullYear();
}