Advertisement
Guest User

js-advanced-table-search-index

a guest
Oct 9th, 2019
1,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement