Advertisement
kstoyanov

03. Delete from Table

Oct 1st, 2020 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function deleteByEmail() {
  2.   const tableTbodyElment = document.querySelector('#customers tbody');
  3.   const tableTrElements = document.querySelectorAll('#customers tbody tr');
  4.   const inputEmailELement = document.querySelector('input[name=email]');
  5.   const result = document.querySelector('#result');
  6.  
  7.   let notFound = true;
  8.  
  9.   if (!inputEmailELement.value) {
  10.     return;
  11.   }
  12.  
  13.   [...tableTrElements].forEach((tr) => {
  14.     const [, email] = tr.querySelectorAll('td');
  15.  
  16.     if (email.innerText === inputEmailELement.value) {
  17.       tableTbodyElment.removeChild(tr);
  18.       notFound = false;
  19.       result.innerText = 'Deleted.';
  20.     }
  21.   });
  22.  
  23.   if (notFound) {
  24.     result.innerText = 'Not found.';
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement