Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 18, 2022 11:48 am GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To