skip to Main Content

Javascript, keypress if i use it when i want user input to be added in a list only one character i.e., the latest pressed key shows up

i wanted to add a userinput in a todo list using keypress but only one character is taken by the input filed. this is the code: input.addEventListener("keypress", function(event){ if(input.value.length>0 && event.key === 'Enter'){ var li = document.createElement("li"); li.appendChild(document.createTextNode(input.value)); ul.appendChild(li); }…

VIEW QUESTION
Back To Top
Search