const clear = document.querySelector(".clear");
const dataElement = document.getElementById("date");
const addTaskClicker = document.querySelector(".add-task-icon");
const addMemberClicker = document.querySelector(".add-member-icon");
const list = document.getElementById("list");
const taskName = document.getElementById("task-name");
const taskDescription = document.getElementById("task-description");
// variables
let LIST, id;
// get data from localstorage
let data = localStorage.getItem("TODO");
// check if data is empty or not
if (data) {
LIST = JSON.parse(data);
id = LIST.length; // set id to the last one in the list
loadList(LIST); // load the list to user interface
} else {
// if data is empty
LIST = [];
id = 0;
}
// load items to the user's interface
function loadList(array) {
array.forEach(function(item) {
addToDo(item.name, item.id, item.description, item.trash);
});
}
// show todays date
const options = {
weekday: "long",
month: "short",
day: "numeric"
};
const today = new Date();
dataElement.innerHTML = today.toLocaleDateString("no-NO", options);
// clear the local storage
clear.addEventListener("click", function() {
localStorage.clear();
location.reload();
});
function addToDo(toDo, id, description, trash) {
if (trash) {
return;
}
const item =
`
<div>
<input type="checkbox" id="${id}" name="toDo" value="task" class="item">
<label for="toDO" class="text taskHeader">${toDo}</label>
<ul>
<li class="description">${description}</li>
</ul>
<i class="trashcan" job="delete" id="${id}"></i>
</div>
`;
const position = "beforeend";
list.insertAdjacentHTML(position, item);
}
addTaskClicker.addEventListener("click", function() {
const toDo = taskName.value;
const description = taskDescription.value;
// if the input isn't empty
if (toDo) {
addToDo(toDo, id, description, false);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.