To-Do Add & Remove
A to-do list where you add and remove items dynamically.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div class="card border-0 shadow-sm" style="max-width:340px"><div class="card-body">
<div class="input-group mb-3"><input class="form-control" id="tdInput" placeholder="New task…"><button class="btn btn-primary" id="tdAdd">Add</button></div>
<ul class="list-group" id="tdList">
<li class="list-group-item d-flex justify-content-between align-items-center">Buy groceries<button class="btn-close" aria-label="Remove"></button></li>
</ul>
</div></div>var inp=document.getElementById('tdInput'),list=document.getElementById('tdList');
function bind(li){li.querySelector('.btn-close').onclick=function(){li.remove()}}
list.querySelectorAll('li').forEach(bind);
function add(){if(!inp.value.trim())return;var li=document.createElement('li');li.className='list-group-item d-flex justify-content-between align-items-center';li.innerHTML=inp.value.trim().replace(/[<>&]/g,'')+'<button class="btn-close" aria-label="Remove"></button>';list.appendChild(li);bind(li);inp.value=''}
document.getElementById('tdAdd').onclick=add;
inp.addEventListener('keydown',function(e){if(e.key==='Enter')add()});Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.