Advertisement
ilianrusev

Christmas Gifts Delivery

Jan 31st, 2022
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2. document.querySelector(".container").addEventListener("click", onClick)
  3.  
  4. function onClick(ev) {
  5.  
  6. let input = document.querySelector("input");
  7. let newLi = document.createElement("li");
  8. newLi.classList = "gift";
  9. let allUL = document.querySelectorAll("ul");
  10. let allButtons = document.querySelectorAll("button");
  11.  
  12. let buttonSend = document.createElement("button");
  13. buttonSend.id = "sendButton";
  14. buttonSend.textContent = "Send";
  15. let buttonDiscard = document.createElement("button");
  16. buttonDiscard.id = "discardButton";
  17. buttonDiscard.textContent = "Discard";
  18.  
  19. if (ev.target == allButtons[0]) {
  20. newLi.textContent = input.value;
  21. newLi.appendChild(buttonSend);
  22. newLi.appendChild(buttonDiscard)
  23. allUL[0].appendChild(newLi);
  24. let ordered = Array.from(allUL[0].children).sort((a, b) => a.textContent.localeCompare(b.textContent))
  25. allUL[0].innerHTML = ordered.map(li => li.outerHTML).join('');
  26. input.value = ""
  27. }
  28.  
  29. if (ev.target.id == "sendButton") {
  30. allUL[1].appendChild(ev.target.parentNode);
  31. ev.target.parentNode.children[1].remove();
  32. ev.target.parentNode.children[0].remove();
  33. // let ordered = Array.from(allUL[1].children).sort((a, b) => a.textContent.localeCompare(b.textContent))
  34. // allUL[1].innerHTML = ordered.map(li => li.outerHTML).join('');
  35. }
  36.  
  37. if (ev.target.id == "discardButton") {
  38. ev.target.parentNode.children[0].remove();
  39. allUL[2].appendChild(ev.target.parentNode);
  40. ev.target.parentNode.children[0].remove();
  41. // let ordered = Array.from(allUL[2].children).sort((a, b) => a.textContent.localeCompare(b.textContent))
  42. // allUL[2].innerHTML = ordered.map(li => li.outerHTML).join('');
  43. }
  44.  
  45. }
  46. }
Advertisement
RAW Paste Data Copied
Advertisement