I'm currently working on a task list project. I’ve been struggling with how to populate the input text onto my card. Ideally, whatever I type into the input field should automatically appear on the card.
I attempted to access the innerHTML
of an input
element as I entered text. However, I couldn’t figure out how to capture the typed input text. My plan was to dynamically create a new element containing the text and then append it to the card.
let btn = document.querySelector('.add');
let textspace = document.querySelector('.todotext');
const input = document.querySelector('input');
// event listener for button click
btn.addEventListener('click', function() {
var txt = document.getElementsByClassName('input').innerHTML;
});
<div class="card">
<div class="todoheader">TODO List</div>
<div class="todotext"></div>
<ul class="list"></ul>
<div class="addtodo">
<button class="add" type="button"> + </button>
<input type="text" class="input" placeholder="add todo" />
</div>
</div>