on-internet
← Community

Create list item from input value

Stack Overflow ·

I'm working on a to-do list project and I got a problem, I want that when I click on the submit button the input value becomes a list item but it doesn't work. Here's the code: let btn = document.getElementById('btn') let txt = document.getElementById('txt') btn.addEventListener('click', function(){ let list = document.createElement('li') list.innerHTML = txt.value }) <h1 id="title">To do list</h1> <div class="main"> <input type="text" alt="type text here" id="txt"> <button type="submit" id="btn">Submit</button> </div>

Comments

Sign in or sign up to comment and upvote.

No comments yet.