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
Asked
Active
Viewed 53 times
-4
-
`getElementByClassName` should be `getElementsByClassName` plural. Same with `getElementByTagName` it's `getElementsByTagName` again. As for `querySelectorAll` it's correct but I suspect you're using it as if it returns a single element: [What do querySelectorAll and getElementsBy* methods return?](https://stackoverflow.com/q/10693845) – VLAZ Sep 15 '22 at 05:45
-
Well first off, neither `getElementByClassName` nor `getElementByTagName` are functions, the actual methods `getElementsByClassName` and `getElementsByTagName` (plural element***s***). Please provide code, and what does this have to do with `google-web-designer`? – Samathingamajig Sep 15 '22 at 05:45
-
thanks for your answer I changed it and it still does not work. mydoc=document.getElementsByClassName("forth"); mydoc.innerHTML="change me please" – moh Sep 15 '22 at 06:40
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 15 '22 at 07:54
1 Answers
0
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];

Will Metcher
- 331
- 1
- 11