Recently I encountered this:
If in the JS:22 line I add this.classlist.add("active");
then it should change the color according to the CSS class, but it does not work. Any idea?
var newItem = 1;
var ourList = document.getElementById("test_id");
var ourButton = document.getElementById("Button_id");
var test_function = document.getElementById("Headline");
var OurListID = document.getElementById("test_id").getElementsByTagName('li')
for (i = 0; i < OurListID.length; i++) {
OurListID[i].addEventListener("click", activateItem );
}
function activateItem () {
test_function.innerHTML = this.innerHTML;
this.classlist.add("active");
}
ourButton.addEventListener("click", NewFunctionName );
function NewFunctionName () {
test_id.innerHTML += "<li>Something New " + newItem + "</li>";
newItem++;
}
/** JavaScriptGenius: 19 min 23 sec - continue **/
.active {
background-color: blue;
}
<!Doctype html>
<html>
<head>
<title>Take me to the paradise city</title>
</head>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<h1 id="Headline">Test Headline</h1>
<p id="IDTest">Click a list item to replace this text.</p>
<button id="Button_id">Add new item</button>
<div>
<ul id="test_id">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>
</div>
<div>
<p>JavaScript Test page</p>
</div>
<script src="JavaScriptGenius.js"></script>
</body>
</html>