Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- document.querySelector('#searchBtn').addEventListener('click', onClick);
- function onClick() {
- let textToMatch = document.getElementById('searchField').value; //searched text
- document.getElementById('searchField').value = ''; //set text to empty for the next click
- //-------------------------------------------------------------------
- let row = document.querySelectorAll('tr')// get all rows
- //-------------------------------------------------------------------
- //-------------------------------------------------------------------
- for (let i = 0; i<row.length; i++)
- {
- row[i].classList.remove('select');
- // clear all classes for the next search
- }
- //-------------------------------------------------------------------
- for (let i = 0; i<row.length; i++)
- {
- let cells = document.getElementsByTagName('tr')[i].document.getElementsByTagName('td');
- // get the cells of the selected row
- for (let cell = 0; i<cells.length; i++)
- {
- if (cells[cell].includes(textToMatch))
- {
- row[i].classList.add('select'); break;
- } // for each row that contains cells with match, add select class to the row
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement