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"; }
5 Respostas
+ 4
Change all the text of #demo child elements to "new text"
+ 1
thanks a lot âșâșâș
know it is clearđđ
0
yes, i know that but i want knowledge What a benefit from use the childNodes and loop in this code
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.
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'