I have put this js code into visual studio and it wont work. Please help:
var task = document.getElementById('action');
var button = document.getElementById('button');
var err = document.getElementById('err');
var list = document.getElementById('tasks');
button.addEventListener("click", function() {
if (task.value == "") {
err.style.backgroundColor = 'red';
err.innerHTML = "Please enter a value";
} else {
var newItem = document.createElement("li");
newItem.innerHTML = task.nodeValue;
list.appendChild(newItem);
err.style.backgroundColor = "none";
err.innerHTML = "";
task.nodeValue = "";
}
})
<header id="header" style="background-color:green;">
<div id="title">To-Do</div>
<div id="date"></div>
</header>
<br>
<hr>
<div id="mains">
<p id="err"></p>
<label for="text">Task: </label>
<input type="text" id="action" name="text" placeholder="Wash the dishes..."><br>
<button id=button>Add</button>
<ul id="tasks"></ul>
</div>
when i press 'add' nothing happens the text remains and ul is unchanged i tried to copy from a post but that also didnt work but was essentially the same as shown above
` needs to be commented. Is that in the real code or a copy ing error?
– Barmar Aug 03 '21 at 19:57