JavaScript – Iterate over Children of HTML Element
To iterate over Children of HTML Element in JavaScript, get the reference to this HTML Element, get children of this HTML using using children
property, then use for loop to iterate over the children.
In the following example, we will get the children elements of the HTML Element which is selected by id "myElement"
, and iterate over the children using for loop. And for each child, we shall modify its font color.
example.html
ADVERTISEMENT
Conclusion
In this JavaScript Tutorial, we learned how to iterate over children of an HTML Element using JavaScript.