Advertisement
Lulunga

DOM 06. Table – Search Engine

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