+ 1
Why it does't work? arr[0].innerHTML
function setText() { var a = document.getElementById("demo"); var arr = a.childNodes; arr[0].innerHTML = "new text"; } setTimeout(setText, 500);
5 ответов
+ 2
make sure that arr[0] is the element you want to modify
you can print arr[0].nodeName to find out
+ 2
Taste Thanks for your quick response.
<html>
<body>
<div id ="demo">
<p>some text</p>
<p>some other text</p>
</div>
</body>
</html>
Just arr[1] outputs "P". Not arr[0]
+ 2
then arr[1] is the node that you want to modify, not 0.
you can loop trough all the childNodes, then in each itteration check the type if its P (or other type of element you expect) then thats the element you re looking for.
+ 2
you're welcome
+ 1
Thank you Taste