mirozspace

tmanager

Oct 22nd, 2020
1,259
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.   let openSection = document.getElementsByTagName("section")[1];
  3.   let inProgressSection = document.getElementsByTagName("section")[2];
  4.   let completeSection = document.getElementsByTagName("section")[3];
  5.  
  6.   let addBtn = document.getElementById("add");
  7.   console.log(addBtn);
  8.  
  9.   addBtn.addEventListener("click", (event) => {
  10.     event.preventDefault();
  11.     let task = document.getElementById("task");
  12.     let description = document.getElementById("description");
  13.     let date = document.getElementById("date");
  14.  
  15.     if (task.value === "" || description.value === "" || date.value === "") {
  16.         return;
  17.       }
  18.  
  19.     let article = document.createElement("article");
  20.     let h3 = document.createElement("h3");
  21.     h3.innerHTML = task.value;
  22.     let pDesc = document.createElement("p");
  23.     pDesc.innerHTML = `Description: ${description.value}`;
  24.     let pDate = document.createElement("p");
  25.     pDate.innerHTML = `Due Date: ${date.value}`;
  26.     let div = document.createElement("div");
  27.     div.className = "flex";
  28.     let startButton = document.createElement("button");
  29.     startButton.textContent = "Start";
  30.     startButton.className = "green";
  31.     let deleteButton = document.createElement("button");
  32.     deleteButton.textContent = "Delete";
  33.     deleteButton.className = "red";
  34.     div.appendChild(startButton);
  35.     div.appendChild(deleteButton);
  36.     article.appendChild(h3);
  37.     article.appendChild(pDesc);
  38.     article.appendChild(pDate);
  39.     article.appendChild(div);
  40.     openSection.children[1].appendChild(article);
  41.  
  42.     startButton.addEventListener('click', (event)=>{
  43.         let newArticle = event.target.parentElement.parentElement;
  44.         newArticle.lastChild.remove();
  45.         let div = document.createElement('div');
  46.         div.appendChild(deleteButton);
  47.         div.className = 'flex';
  48.         let finishButton = document.createElement('button');
  49.         finishButton.className = 'orange';
  50.         finishButton.textContent = 'Finish';
  51.         div.appendChild(finishButton);
  52.         newArticle.appendChild(div);
  53.         inProgressSection.children[1].appendChild(newArticle);
  54.         //event.target.parentElement.parentElement.remove();
  55.  
  56.         finishButton.addEventListener('click', (event)=>{
  57.             let newArticle = event.target.parentElement.parentElement;
  58.             newArticle.lastChild.remove();
  59.             completeSection.children[1].appendChild(newArticle);
  60.         })
  61.     })
  62.  
  63.     deleteButton.addEventListener('click', (event)=>{
  64.         event.target.parentElement.parentElement.remove()
  65.     })
  66.  
  67.     console.log(123);
  68.     task.value = description.value = date.value = "";
  69.   });
  70. }
  71.  
RAW Paste Data