Skip to main content

To Do List : Javascript Code

 


const inputbox = document.getElementById("input-box")
const listcontainer = document.getElementById("list-container")

function addTask() {
    if (inputbox.value === '') {
        alert("you must write something! Example your Frist task like 'Homework'");
    }
    else {
        let li = document.createElement("li");
        li.innerHTML = inputbox.value;
        listcontainer.appendChild(li);
        let span = document.createElement("span")
        span.innerHTML = "\u00d7";
        li.appendChild(span);
    }
    inputbox.value = "";
    saveData();
}

listcontainer.addEventListener("click", function (e) {
    if (e.target.tagName === "LI") {
        e.target.classList.toggle("checked");
        saveData();
    }
    else if (e.target.tagName === "SPAN") {
        e.target.parentElement.remove();
        saveData();
    }
}, false);

function saveData() {
    localStorage.setItem("data", listcontainer.innerHTML);
}
function ShowTask() {
    listcontainer.innerHTML = localStorage.getItem("data");
}
ShowTask();

Comments

Popular posts from this blog

Grocery kart : Html and CSS

  HTML ==   < footer class = "footer" >     < div class = "container" >       < div class = "row" >         < div class = "footer-col" >           < h4 > company </ h4 >           < ul >             < li >< a href = "#" > about us </ a ></ li >             < li >< a href = "#" > our services </ a ></ li >             < li >< a href = "#" > privacy policy </ a ></ li >             < li >< a href = "#" > affiliate program </ a ></ li >           </ ul >         </ div >         < div class = "footer-col" >           ...