0

please i want any one explain this code🤔🤔

function setText() { var a = document.getElementById("demo"); var arr = a.childNodes; for(var x=0;x<arr.length;x++) { arr[x].innerHTML = "new text"; }

3rd May 2017, 4:25 AM
Shroq Khaled Mahdi Al-Nabhani
Shroq Khaled Mahdi Al-Nabhani - avatar
5 odpowiedzi
+ 4
Change all the text of #demo child elements to "new text"
3rd May 2017, 4:30 AM
Calviղ
Calviղ - avatar
+ 1
thanks a lot ☺☺☺ know it is clear😊😊
3rd May 2017, 5:05 AM
Shroq Khaled Mahdi Al-Nabhani
Shroq Khaled Mahdi Al-Nabhani - avatar
0
yes, i know that but i want knowledge What a benefit from use the childNodes and loop in this code
3rd May 2017, 4:34 AM
Shroq Khaled Mahdi Al-Nabhani
Shroq Khaled Mahdi Al-Nabhani - avatar
0
If you have a list with heading as Parent node and items in the list has child node lyk Products a b c By getting the id of products we can change all the elements that come under products like a,b,c to the desired future we want. Useful when you want a all elements in a group to pocess same features.
3rd May 2017, 5:01 AM
Nantha
Nantha - avatar
0
Since you dont know how big the 'demo' will be, childNodes gives you that information so that you can change all of the text under 'demo'
5th May 2017, 5:50 PM
Zorry Serafimova
Zorry Serafimova - avatar