InnerHTML won't change firstChild | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

InnerHTML won't change firstChild

I've changed code slightly to use firstChild but it doesn't update the result, original code is commented off for comparison, why isn't it working? https://code.sololearn.com/WU9RUlQgu22Z/?ref=app

24th Jul 2017, 8:48 AM
Dawid Serafinowski
Dawid Serafinowski - avatar
3 Answers
+ 1
This one worked: a.childNodes[1].innerHTML = "new text"
24th Jul 2017, 8:59 AM
Drax
Drax - avatar
0
guess firstChild is ok for lists
24th Jul 2017, 9:44 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
0
Drax, yes this "array" approach works. I just wonder why firstChild/lastChild way isn't doing anything. Alerting firstChild.innerHTML does display the value but as Claudiu Stefan Haidu said it must be that it only works for listing and not for making any changes. Thanks guys.
24th Jul 2017, 11:13 AM
Dawid Serafinowski
Dawid Serafinowski - avatar