Traverse DOM elements with each function

Asked

Viewed 42 times

-3

I would like an example of how I could do this using Jquery

1 answer

1


Hello, see an example of how you could do,

$('#my-list li').each(function(index, element) {
  console.log(index + ' : ' + element.innerHTML);
});
<ol id="my-list">
  <li>Red</li>
  <li>Green</li>
  <li>Yellow</li>
  <li>Blue</li>
</ol>

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

See if this helps!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.