kstoyanov

06. Table – Search Engine

Oct 1st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let dataTr = Array.from(document.querySelectorAll('tbody > tr'));
  3.     let searchBtn = document.querySelector("#searchBtn");
  4.     let searchField = document.querySelector("#searchField");
  5.     searchBtn.addEventListener('click', function () {
  6.         let regex = new RegExp(searchField.value, 'gim');
  7.         dataTr.map(e => {
  8.             e.classList.remove('select');
  9.             if (e.innerText.match(regex) !== null) {
  10.                 e.className = 'select';
  11.             }
  12.         });
  13.         searchField.value = '';
  14.     });
  15. }
Add Comment
Please, Sign In to add comment