Advertisement
Lulunga

06. Table – Search Engine DOM

Oct 12th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function solve() {
  3.    let input = document.getElementById('searchField');
  4.    let body = document.querySelectorAll('tbody tr');
  5.  
  6.    if (input === null || body === null) {
  7.       throw new Error('Missing HTML elements!');
  8.    }
  9.  
  10.    document.getElementById('searchBtn').addEventListener('click', main);
  11.    function main() {
  12.       for (let tr of body) {
  13.          tr.classList.remove('select');
  14.       }
  15.       if (input.value == '') {
  16.          return '';
  17.       }
  18.       for (let tr of body) {
  19.          if (tr.textContent.includes(input.value)) {
  20.             tr.classList.add('select');
  21.          }
  22.       }
  23.       input.value = '';
  24.    }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement