loop and find class

PHOTO EMBED

Thu Oct 06 2022 05:55:26 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #javascript #matches #classes #find

<ul id="birds">
  <li>Orange-winged parrot</li>
  <li class="endangered">Philippine eagle</li>
  <li>Great white pelican</li>
</ul>



<script>
    
const birds = document.querySelectorAll('li');

for (const bird of birds) {
  if (bird.matches('.endangered')) {
    console.log(`The ${bird.textContent} is endangered!`);
  }
}

    </script>
content_copyCOPY