This question already has an answer here:
I just started learning DOM Manipulation and want to do a simple task of changing the font color of h1 using javaScript but I am getting this error - "Cannot read property 'style' of null ". My js file is connected to html but the next line is not working. Please help.
demo.html
<!DOCTYPE html>
<html>
<head>
<title>My Site</title>
<script type="text/javascript" src="demo.js"></script>
</head>
<body>
<h1>My Website</h1>
</body>
</html>
demo.js
alert("connected");
var h1=document.querySelector("h1");
h1.style.color="pink";
Aucun commentaire:
Enregistrer un commentaire