I am trying to change the text color using getElementsByClassName. .Explain why javascript is failing to achieve this?
document.getElementsByClassName("myH1").style.text-color = "red";
<h1 class="myH1">How to change the style of a header</h1>
Uncaught TypeError: Cannot set property 'color' of undefined
document.getElementsByClassName("myH1").style.color = "red";
Asked
Active
Viewed 244 times
0

mansi
- 1
- 1
-
Check: http://stackoverflow.com/questions/42599612/cannot-change-class-of-img-tag/42599693#42599693 – kind user Mar 04 '17 at 23:29
-
This is a duplicate of both [What do `querySelectorAll`, `getElementsByClassName` and other `getElementsBy*` methods return?](http://stackoverflow.com/q/10693845/4642212) and [How do I reference a javascript object property with a hyphen in it?](http://stackoverflow.com/q/7122609/4642212). – Sebastian Simon Mar 04 '17 at 23:37