MCPcopy Create free account
hub / github.com/codemistic/Web-Development / add_item

Function add_item

TO-DO-List/main.js:2–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1// Function called while clicking add button
2function add_item() {
3
4// Getting box and ul by selecting id;
5let item = document.getElementById("box");
6let list_item = document.getElementById("list_item");
7if(item.value != ""){
8
9 // Creating element and adding value to it
10 let make_li = document.createElement("LI");
11 make_li.appendChild(document.createTextNode(item.value));
12
13 // Adding li to ul
14 list_item.appendChild(make_li);
15
16 // Reset the value of box
17 item.value=""
18
19 // Delete a li item on click
20 make_li.onclick = function(){
21 this.parentNode.removeChild(this);
22 }
23
24}
25else{
26
27 // Alert msg when value of box is "" empty.
28 alert("Please add an item in To-do list");
29}
30
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected