Giter Site home page Giter Site logo

to-do-list-app's Introduction

#To Do List App Alt text Alt text

//SELECT CLASSES FROM HTML
const inputBox = document.getElementById('input-box');
const listContainer = document.getElementById('list-container');

//adding click function to the button [in HTML onclick="addTask()"]

function addTask() {
  if (inputBox.value === '') {
    alert("You must write something");
    
//so this happen when click button and dont have any task in the input text field

}
  else {  //create a new li element    
  //this line create and stores new element in the "li" variable
    let li = document.createElement("li"); 
    //this detect the text we added in the input so we are adding li overwritten with your task the li in the HTML
    li.innerHTML = inputBox.value;
    //this displays the li
    listContainer.appendChild(li);
***************up to here the app still holds and keep the li so we need to add code to erase the task for addinga new task*********
↓//this add cross icon at the end of the task list item //"\u00d7" is the cros icon code
↓    let span = document.createElement("span");
↓    span.innerHTML = "\u00d7"
↓    li.appendChild(span);
↓  }
→ inputBox.value = '';
  saveData();
}

listContainer.addEventListener("click", function (e) {
  //The code inside this listener event will be executed whenever there is a click on an item within.. WHAT IT MEANS IS THAT WHENEVER YOU CLICK THE TASK, THE TASK WILL APPEAR CHECHED WITH A MID-LINE AND THE CHECKED IMG. IF YOU CLICK IT TWICE THE TASK WILL BE UNCHECKED ALSO.
  //the list container. If the clicked item was a span, remove it from its parent li
  if (e.target.tagName === 'LI') {
    e.target.classList.toggle("checked");
    saveData();
  }
  else if (e.target.tagName === "SPAN") {
    e.target.parentElement.remove();
    saveData();
  }
}, false);


//FUNCTION TO STORE DATA THAT MEANS IF YOU ARE GONE AND CLOSE BROWSER, THE BROWSER WILL KEEP DAT OF YOUR TASKS** CHECK IT OUT THAT YOU HAVE savedata() in the other functions also.
function saveData() {
  localStorage.setItem("data", listContainer.innerHTML);
}

function showTask() {
  listContainer.innerHTML = localStorage.getItem("data");
}
showTask();

taken from https://www.youtube.com/watch?v=G0jO8kUrg-I&>ab_channel=GreatStack

to-do-list-app's People

Watchers

The-Shugga'-Rush avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.