Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution() {
- const [addSection, listSection, sentSection, discartedSection] = Array.from(document.getElementsByClassName("card"));
- const addInput = addSection.querySelector("input");
- const btnAdd = addSection.querySelector("button");
- btnAdd.addEventListener("click", function () {
- if (addInput.value !== "") {
- let li = document.createElement("li");
- li.classList.add("gift");
- li.textContent = addInput.value;
- let btnSend = document.createElement("button");
- btnSend.id = "sendButton";
- btnSend.textContent = "Send";
- let btnDiscard = document.createElement("button");
- btnDiscard.id = "discardButton";
- btnDiscard.textContent = "Discard";
- li.appendChild(btnSend);
- li.appendChild(btnDiscard);
- listSection.querySelector("ul").appendChild(li);
- //-------------------------------------------------------------------------------------------------------
- let allListItems = Array.from(listSection.querySelectorAll("ul li")).sort((a, b) => a.textContent.localeCompare(b.textContent))
- listSection.querySelector("ul").innerHTML = "";
- allListItems.forEach(element => listSection.querySelector("ul").appendChild(element));
- //---------------------------------------------------------------------------------------------------------
- addInput.value = "";
- btnSend.addEventListener("click", function (e) {
- let giftSend = e.target.parentNode.firstChild.textContent;
- let liSend = document.createElement("li");
- liSend.textContent = giftSend;
- sentSection.querySelector("ul").appendChild(liSend);
- e.target.parentNode.remove();
- });
- btnDiscard.addEventListener("click", function (e) {
- let giftSend = e.target.parentNode.firstChild.textContent;
- let liSend = document.createElement("li");
- liSend.textContent = giftSend;
- discartedSection.querySelector("ul").appendChild(liSend);
- e.target.parentNode.remove();
- });
- }
- });
- }
Add Comment
Please, Sign In to add comment