I'm learning DOM manipulation as a beginner and have selected the tag in variable h. My online instructor is able to access h.style, but for me it doesn't work. My code:
<!DOCTYPE html>
<html>
<head>
<title>
DOM Manipulation Basics
</title>
</head>
<body>
<h1> Hello </h1>
</body>
</html>
Here's what happens in the console:
var h=document.getElementsByTagName("h1");
undefined
h
HTMLCollection [h1]0: h1length: 1__proto__: HTMLCollection
h.style;
undefined
h[0].style;
CSSStyleDeclaration {alignContent: "", alignItems: "", alignSelf: "", alignmentBaseline: "", all: "", …}
h.style.color="red";
VM999:1 Uncaught TypeError: Cannot set property 'color' of undefined
at <anonymous>:1:14
(anonymous) @ VM999:1
h[0].style.color="red";
"red"