An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
May 18, 2022 11:48 am GMT
Original Link: https://dev.to/greggcbs/simplest-way-to-loop-node-list-htmlcollection-using-map-foreach-etc-54mj
Simplest way to loop node list / HTMLCollection using map, foreach etc
You spread the list like this:
const elements = document.getElementsByClassName('modal');[...elements].forEach((element)=> { console.log(element)})
Or in one line like this, this is useful if you are doing multiple loops and do not want to spread every time:
const elements = [...document.getElementsByClassName('modal')];elements.forEach((element)=> { console.log(element)})
Original Link: https://dev.to/greggcbs/simplest-way-to-loop-node-list-htmlcollection-using-map-foreach-etc-54mj
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To