Advertisement
viligen

searchInList2_DOM

May 29th, 2022
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function search() {
  2.     let matches = Array.from(document.querySelectorAll("#towns li"));
  3.     matches.map(
  4.         (m) => (m.style = "font-weight: normal; text-decoration: none")
  5.     );
  6.    
  7.     let resultNum = 0;
  8.     let searchedText = document.getElementById("searchText").value;
  9.  
  10.     let resultEl = document.getElementById("result");
  11.     resultEl.textContent = 0;
  12.  
  13.     let filtered = matches.filter((m) => m.textContent.includes(searchedText));
  14.    
  15.     filtered.map(
  16.         (m) => (m.style = "font-weight: bold; text-decoration: underline")
  17.     );
  18.  
  19.     resultNum = filtered.length;
  20.  
  21.     resultEl.textContent = `${resultNum} matches found`;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement