Advertisement
ilianrusev

SoftBlog

Jan 31st, 2022
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2. document.getElementsByClassName('btn create')[0].type = 'button';
  3. let creator = document.getElementById("creator");
  4. let title = document.getElementById("title");
  5. let category = document.getElementById("category");
  6. let content = document.getElementById("content");
  7. let createBtn = document.getElementsByClassName('btn create')[0]
  8.  
  9.  
  10. createBtn.addEventListener("click", create);
  11. function create() {
  12. let article = document.createElement("article");
  13.  
  14. let h1 = document.createElement("h1");
  15. h1.textContent = title.value;
  16.  
  17. let categoryP = document.createElement("p");
  18. let firstStrong = document.createElement("strong");
  19. firstStrong.textContent = category.value
  20. categoryP.textContent = "Category: ";
  21. categoryP.appendChild(firstStrong);
  22.  
  23. let creatorP = document.createElement("p");
  24. let secondStrong = document.createElement("strong");
  25. secondStrong.textContent = creator.value;
  26. creatorP.textContent = "Creator: ";
  27. creatorP.appendChild(secondStrong)
  28.  
  29. let contentP = document.createElement("p");
  30. contentP.textContent = content.value
  31.  
  32. let divButtons = document.createElement("div");
  33. divButtons.classList = "buttons";
  34.  
  35. let deleteBtn = document.createElement("button");
  36. deleteBtn.classList="btn delete";
  37. deleteBtn.textContent="Delete"
  38.  
  39. let archiveBtn = document.createElement("button")
  40. archiveBtn.classList="btn archive";
  41. archiveBtn.textContent="Archive"
  42.  
  43. divButtons.appendChild(deleteBtn);
  44. divButtons.appendChild(archiveBtn);
  45.  
  46. article.appendChild(h1);
  47. article.appendChild(categoryP);
  48. article.appendChild(creatorP);
  49. article.appendChild(contentP);
  50. article.appendChild(divButtons);
  51.  
  52. document.querySelector("main section").appendChild(article);
  53.  
  54. title.value = ""
  55. creator.value = ""
  56. category.value = ""
  57. content.value = ""
  58.  
  59.  
  60.  
  61. deleteBtn.addEventListener("click", deletes)
  62.  
  63. function deletes() {
  64. document.querySelector("main section").removeChild(article)
  65. }
  66.  
  67.  
  68.  
  69. archiveBtn.addEventListener("click",archive)
  70.  
  71. function archive() {
  72. let ol = document.querySelector("ol")
  73. let li = document.createElement("li")
  74. li.textContent = h1.textContent;
  75. ol.appendChild(li)
  76. let ordered = Array.from(document.querySelectorAll("li")).sort((a,b)=> a.textContent.localeCompare(b.textContent))
  77. ol.innerHTML = ordered.map(li => li.outerHTML).join('');
  78.  
  79. document.querySelector("main section").removeChild(article)
  80. }
  81. }
  82.  
  83.  
  84. }
  85.  
Advertisement
RAW Paste Data Copied
Advertisement