This is my first project ever. I'm trying to make a simple to-do list for practice. One writes something, anything, on an input type text and it's supposed to show up below as a numbered list. Right next to the item in the list, there's supposed another button that eliminates the item.
How do I make it be a numbered list as I add items through the input text and how, at the same time, do I add input buttons along with the item? How do I stop it from adding items when the input text is still empty?
My code so far:
HTML
<div>
<input type="text" placeholder="Add an item!" id="text1" class="text1" />
<input type="button" value="Submit" id="button1" />
<input type="button" value="Clear List" id="button2" />
<p id="write"></p>
</div>
JS
var input2 = document.getElementById("button1");
input2.addEventListener("click", addStuff);
function addStuff() {
todo = text1.value;
add.innerHTML += todo + "<br />";
}
I encourage you to create it on your own with the help of the following list. But if you get stuck you can use ready-made code.
<ol>
tag to which notes will be added.innerHTML
method.remove()
method.addStuff
method, take the value of the text field. Then create abutton
andli
with thecreateElement
method, add the required attributes to each of them, and appendbutton
toli
andli
to theol
list.Usefull links