loop through htmlcollection
snippet in html

loop through htmlcollection

user3211

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>For loop for HTMLCollection elements</title> 
</head> 
  
<body> 
    <h1 style="color: green">GeeksforGeeks</h1> 
    <b>For loop for HTMLCollection elements</b> 
    <p>This is paragraph 1.</p> 
    <p>This is paragraph 2.</p> 
    <script type="text/javascript"> 
        // get a HTMLCollection of elements in the page 
        let collection = document.getElementsByTagName("p"); 
  
        // regular for loop 
        for (let i = 0; i < collection.length; i++) { 
            console.log(collection[i]); 
        } 
    </script> 
</body> 
  
</html>