{element.innerHTML="text Changed";}); There is also an html file:
I have two files, one is a js file:
const a = document.getElementsByTagName("body")[0]; const d = a.getElementsByTagName("h1"); d.forEach(element => { element.innerHTML = "Text changed"; });
There is also an html file:
David Hello 1
David
Ariel
Yahav
Hello 2
Hello 3
I tried to change the text of each h1 element to the same text, but it didn't work, that is when I run it on the browser, all the "h1" text still remains the same.
Not sure why, since "d" is a html collection and I use foreach to run on it.
Basically everything is pretty simple so not sure what I can try.
Thanks for any help!
You should not use
forEach
because HTMLCollections does not implement the forEach method.Use for loop