Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- //TODO..
- const btnAdopt= document.getElementById('adopt-btn');
- const InputType=document.getElementById('type');
- const InputGender=document.getElementById('gender');
- const InputAge=document.getElementById('age');
- btnAdopt.addEventListener('click',(e)=>{
- e.preventDefault();
- if(!InputType.value || !InputGender.value || !InputAge.value){
- return;
- }
- //console.log('success');
- const ElementListAdotion=document.getElementById('adoption-info');
- const Elementadoptedlist=document.getElementById('adopted-list');
- const Elementp1= document.createElement('p');
- Elementp1.textContent=`Pet:${InputType.value}`;
- const Elementp2= document.createElement('p');
- Elementp2.textContent=`Gender:${InputGender.value}`;
- const Elementp3= document.createElement('p');
- Elementp3.textContent=`Age:${InputAge.value}`;
- const ArticleEl=document.createElement('article');
- ArticleEl.appendChild(Elementp1);
- ArticleEl.appendChild(Elementp2);
- ArticleEl.appendChild(Elementp3);
- //btns
- const EditBtn=document.createElement('button');
- EditBtn.classList.add('edit-btn');
- EditBtn.textContent='Edit';
- const DoneBtn=document.createElement('button');
- DoneBtn.classList.add('done-btn');
- DoneBtn.textContent='Done';
- const ButtonContainer=document.createElement('div');
- ButtonContainer.classList.add('buttons');
- ButtonContainer.appendChild(EditBtn);
- ButtonContainer.appendChild(DoneBtn);
- const LiElement= document.createElement('li');
- LiElement.appendChild(ArticleEl);
- LiElement.appendChild(ButtonContainer);
- ElementListAdotion.appendChild(LiElement);
- InputType.value='';
- InputGender.value='';
- InputAge.value='';
- EditBtn.addEventListener('click',()=>{
- let ListNodes=document.querySelectorAll('article p');
- let AllList= Array.from(ListNodes);
- InputType.value=AllList[0].textContent.substring(4);
- InputGender.value=AllList[1].textContent.substring(7);
- InputAge.value=AllList[2].textContent.substring(4);
- LiElement.remove();
- });
- DoneBtn.addEventListener('click',()=>{
- Elementadoptedlist.appendChild(LiElement);
- //DoneBtn.remove();
- //EditBtn.remove();
- ButtonContainer.remove();
- const BtnClear= document.createElement('button');
- BtnClear.classList.add('clear-btn');
- BtnClear.textContent='Clear';
- LiElement.appendChild(BtnClear);
- BtnClear.addEventListener('click',()=>{
- LiElement.remove();
- });
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement