Advertisement
Stan0033

Untitled

Feb 13th, 2022
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. function solve() {
  2. document.querySelector('#searchBtn').addEventListener('click', onClick);
  3.  
  4. function onClick() {
  5. let textToMatch = document.getElementById('searchField').value; //searched text
  6. document.getElementById('searchField').value = ''; //set text to empty for the next click
  7. //-------------------------------------------------------------------
  8.  
  9. let row = document.querySelectorAll('tr')// get all rows
  10.  
  11. //-------------------------------------------------------------------
  12. //-------------------------------------------------------------------
  13. for (let i = 0; i<row.length; i++)
  14. {
  15.  
  16. row[i].classList.remove('select');
  17. // clear all classes for the next search
  18. }
  19. //-------------------------------------------------------------------
  20.  
  21. for (let i = 0; i<row.length; i++)
  22. {
  23.  
  24. let cells = document.getElementsByTagName('tr')[i].document.getElementsByTagName('td');
  25. // get the cells of the selected row
  26.  
  27. for (let cell = 0; i<cells.length; i++)
  28. {
  29. if (cells[cell].includes(textToMatch))
  30. {
  31. row[i].classList.add('select'); break;
  32. } // for each row that contains cells with match, add select class to the row
  33. }
  34.  
  35. }
  36.  
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement