Advertisement
Silviya7

2.ContactList

Apr 16th, 2024
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     //...TODO
  3.  
  4.     const AddBtn= document.getElementById('add-btn');
  5.     const ElementName= document.getElementById('name');
  6.     const ElementPhone= document.getElementById('phone');
  7.     const ElementCAtegory= document.getElementById('category');
  8.  
  9.     const CheckList= document.getElementById('check-list');
  10.  
  11.  
  12.     AddBtn.addEventListener(('click'),()=>{
  13.  
  14.       const Elementp1=document.createElement('p');
  15.       Elementp1.textContent=`name:${ElementName.value}`;
  16.  
  17.       const Elementp2=document.createElement('p');
  18.       Elementp2.textContent=`phone:${ElementPhone.value}`;
  19.       const Elementp3=document.createElement('p');
  20.       Elementp3.textContent=`category:${ElementCAtegory.value}`;
  21.  
  22.       const Article= document.createElement('article');
  23.       Article.appendChild(Elementp1);
  24.       Article.appendChild(Elementp2);
  25.       Article.appendChild(Elementp3);
  26.  
  27.        const ElementLi= document.createElement('li');
  28.  
  29.       const ContainerButtons= document.createElement('div');
  30.       ContainerButtons.classList.add('buttons');
  31.  
  32.       const BtnEdit=document.createElement('button');
  33.       BtnEdit.classList.add('edit-btn');
  34.       const BtnSave=document.createElement('button');
  35.       BtnSave.classList.add('save-btn');
  36.       ContainerButtons.appendChild(BtnEdit);
  37.       ContainerButtons.appendChild(BtnSave);
  38.  
  39.       ElementLi.appendChild(Article);
  40.       ElementLi.appendChild(ContainerButtons);
  41.       CheckList.appendChild(ElementLi);
  42.  
  43.        ElementName.value='';
  44.        ElementPhone.value='';
  45.        ElementCAtegory.value='';
  46.  
  47.        //editBtn
  48.        BtnEdit.addEventListener('click',()=>{
  49.         let ListNodes=document.querySelectorAll('article p');
  50.         let AllList= Array.from(ListNodes);
  51.  
  52.        
  53.        ElementName.value= AllList[0].textContent.substring(5);
  54.        ElementPhone.value=AllList[1].textContent.substring(6);
  55.        ElementCAtegory.value= AllList[2].textContent.substring(9);
  56.        ElementLi.remove();
  57.        });
  58.  
  59.        //saveBtn
  60.        BtnSave.addEventListener('click',()=>{
  61.        
  62.  
  63.         const DivContact= document.getElementById('contact-list');
  64.         DivContact.appendChild(ElementLi);
  65.  
  66.         BtnEdit.remove();
  67.         BtnSave.remove();
  68.  
  69.         const DeleteBtn= document.createElement('button');
  70.         DeleteBtn.classList.add('del-btn');
  71.         ElementLi.appendChild(DeleteBtn);
  72.  
  73.         DeleteBtn.addEventListener('click',()=>{
  74.  
  75.           ElementLi.remove();
  76.         })
  77.  
  78.        });
  79.  
  80.     })
  81.  
  82.  
  83.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement