- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
30 lines (24 loc) · 677 Bytes
/
Copy pathscript.js
File metadata and controls
30 lines (24 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
varbutton=document.getElementById("enter");
varinput=document.getElementById("userinput");
varul=document.querySelector("ul");
functioninputLength(){
returninput.value.length;
}
functioncreateListElement(){
varli=document.createElement("li");
li.appendChild(document.createTextNode(input.value));
ul.appendChild(li);
input.value="";
}
functionaddListAfterClick(){
if(inputLength()>0){
createListElement();
}
}
functionaddListAfterKeypress(event){
if(inputLength()>0&&event.keyCode===13){
createListElement();
}
}
button.addEventListener("click",addListAfterClick);
input.addEventListener("keypress",addListAfterKeypress);