why can't i change my html content by queryselectorall and getelementbyclass name?

Viewed 28

why my console does not recognize the getElementByClassName and getElementByTagName and querySelectorAll methods while it know getElementById and querySelector?and I can not change the style with querySelector

1 Answers

mydoc=document.getElementsByClassName("forth"); returns a HTMLCollection object. HTMLCollection does not have a innerHTML property. You need to access a specific element of the collection through it's index. I.e.

mydoc[0].innerHTML = "change me please"; or mydoc = document.getElementsByClassName("forth")[0];

Related