I've started using atom to code my HTML, CSS and JS files, but have ran into some issue getting JS to work with the HTML document. I have the following code in place with the corresponding file names:
Code:
var h1 = document.querySelector('h1');
h1.onclick = function(){
this.classList.add('highlight');
}
CSS:
.highlight {
color: white;
background-color: blue;
}
h1 {
font-style: italic;
}
<html>
<head>
<title>Applying Multiple Styles</title>
</head>
<body>
<h1>Highlight this element on a click</h1>
</body>
</html>
When opening up the file via chrome I see:
Showing the title to be italic, meaning the CSS has worked, but upon clicking the text, it does not change colour like the JS says it should so the JS doesn't work but the CSS does? Any thoughts?