Hi everyone! I'm the author of code.mu :)
I'd love to chat with my non-Russian audience. I'm looking for your feedback on the site and the translation quality. Let's chat:)
⊗jsPmNdLI 394 of 504 menu
◀ ▶

Loop iteration of nodes in JavaScript

As you should already know, the property children contains all DOM elements that are direct children of this element. There is a similar property childNodes which contains all child nodes of an element.

Let's, for example, use this property to display various nodes from our element:

console.log(elem.childNodes[0]); console.log(elem.childNodes[1]); console.log(elem.childNodes[2]);

And now let's iterate over the nodes of the element in a loop:

for (let node of elem.childNodes) { console.log(node); }

Given a div:

<div id="elem">txt<b>tag</b><!--com-->txt<b>tag</b><!--com--></div>

Loop through all the nodes of this div and print them to the console.

← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline