Advertisement
go6odn28

exam- 02.Adopt Me

Dec 2nd, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener("load", solve);
  2.  
  3. function solve() {
  4.  
  5.  
  6.     const adoptButton = document.getElementById("adopt-btn")
  7.  
  8.     adoptButton.addEventListener("click", (event) => {
  9.  
  10.         event.preventDefault();
  11.  
  12.         const animal = document.getElementById("type").value
  13.         const age = document.getElementById("age").value
  14.         const gender = document.getElementById("gender").value
  15.  
  16.         const adoptionInfo = document.getElementById("adoption-info")
  17.         const list = document.createElement("li")
  18.         const article = document.createElement('article')
  19.         const div = document.createElement("div")
  20.  
  21.         const editButton = document.createElement('button')
  22.         const doneButton = document.createElement('button')
  23.         const animalElement = document.createElement("p")
  24.         const ageElement = document.createElement("p")
  25.         const genderElement = document.createElement("p")
  26.  
  27.         editButton.className = "edit-btn"
  28.         editButton.textContent = "Edit"
  29.         doneButton.className = "done-btn"
  30.         doneButton.textContent = "Done"
  31.  
  32.         animalElement.textContent = `Pet:${animal}`
  33.         ageElement.textContent = `Age:${age}`
  34.         genderElement.textContent = `Gender:${gender}`
  35.         div.classList.add("buttons");   // TODO САМО ДОБАВИХ КЛАСА ЗА БУТОНИТЕ
  36.  
  37.         adoptionInfo.appendChild(list)
  38.         div.appendChild(editButton)
  39.         div.appendChild(doneButton)
  40.         list.appendChild(article)
  41.         article.appendChild(animalElement)
  42.         article.appendChild(genderElement)
  43.         article.appendChild(ageElement)
  44.         list.appendChild(div)
  45.  
  46.         document.getElementById('type').value = ""
  47.         document.getElementById('age').value = ""
  48.         document.getElementById('gender').value = ""
  49.  
  50.         adoptButton.disabled = true
  51.  
  52.         editButton.addEventListener("click", () => {
  53.  
  54.             adoptButton.disabled = false
  55.  
  56.             document.getElementById('type').value = animal
  57.             document.getElementById('age').value = age
  58.             document.getElementById('gender').value = gender
  59.  
  60.             animalElement.textContent = ''
  61.             ageElement.textContent = ''
  62.             genderElement.textContent = ''
  63.  
  64.             list.remove()
  65.         })
  66.  
  67.         doneButton.addEventListener('click', () => {
  68.  
  69.             adoptButton.disabled = false
  70.  
  71.             list.remove()
  72.             const adoptedList = document.getElementById('adopted-list')
  73.             adoptedList.appendChild(list)
  74.             div.remove()
  75.             const clearButton = document.createElement('button')
  76.             clearButton.className = 'clear-btn'
  77.             clearButton.textContent = 'Clear'
  78.             list.appendChild(clearButton)
  79.  
  80.             clearButton.addEventListener('click', () => {
  81.                 list.remove()
  82.             })
  83.         })
  84.  
  85.     })
  86.  
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement