Advertisement
Silviya7

5.Table - Search Engine

Apr 4th, 2024
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.    document.querySelector('#searchBtn').addEventListener('click', onClick);
  3.  
  4.    function onClick() {
  5.       //   TODO:
  6.   const listTr= document.querySelectorAll('table.container tbody tr');
  7.   const searchfield= document.querySelector('#searchField');
  8.  
  9.   for (const trel of listTr) {
  10.    
  11.    const listv=trel.querySelectorAll('td');
  12.    let issearched= false;
  13.  
  14.    trel.className='';
  15.    for (const el of listv) {
  16.      
  17.      if(el.textContent.toLowerCase().includes(searchfield.value) ){
  18.       issearched= true;
  19.       break;
  20.      }
  21.    }
  22.    if(issearched ==true){
  23.       trel.className='select';
  24.    }
  25.   }
  26.    }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement