Advertisement
Silviya7

CssSelectors

Apr 4th, 2024
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function search() {
  2.    const listTown= document.getElementById('towns');
  3.  
  4.    const resultElement=document.getElementById('result');
  5.    const searchtext= document.querySelector('#searchText').value;
  6.  
  7.    let matchcount=0;
  8.    const townElements=Array.from(listTown.children);
  9.    for (const town  of townElements) {
  10.       if (town.innerHTML.includes(searchtext)) {
  11.          town.style.textDecoration='underline';
  12.          town.style.fontWeight='bold';
  13.          matchcount++;
  14.       }
  15.    }
  16.  
  17.    const res=`${matchcount} matches found`;
  18.    resultElement.textContent=res;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement