+ 1

why won't this javascript function work

... it's supposed to change the name from alex simpson to Peter parker but it does nothing..no errors, just nothing https://code.sololearn.com/WnOGF7NPfj89/?ref=app

2nd Oct 2020, 8:41 AM
Sheldon 10110
Sheldon 10110 - avatar
8 Respostas
+ 7
Empty lines will be considered as text child node. arr[0] is text node arr[1] is img tag arr[2] is again text node arr[3] is p tag (this is what you want to edit)
2nd Oct 2020, 8:47 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 5
Use arr[3] instead of 1
2nd Oct 2020, 8:45 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 3
Will one of you blue stars please explain how you come to know that it is the third element of arr nodelist that should be used?
2nd Oct 2020, 9:20 AM
ODLNT
ODLNT - avatar
+ 2
Why don't use a query selector like document.querySelector("#header p").innerHTML = "New Name" and save some headache.
2nd Oct 2020, 8:53 AM
CHMD
CHMD - avatar
+ 2
childNodes is a NodeList of all nodes in a element (including text nodes) <div> Hello <p id="p">world</p> </div> Contains 3 childNodes - TextNode - " Hello" - HTMLParagraphElement - #p - TextNode - "" Solution 👇 Change a.childNodes to a.children
2nd Oct 2020, 9:06 AM
Ore
Ore - avatar
+ 1
ODLNT console.log([...arr]) That is it
2nd Oct 2020, 9:26 AM
Ore
Ore - avatar
+ 1
RDC it works now,thanks....but... I dont see any empty lines in the <div> ,..so I'm a bit confused
2nd Oct 2020, 9:30 AM
Sheldon 10110
Sheldon 10110 - avatar
- 4
cuz your bad
2nd Oct 2020, 8:45 AM
Fabian Thompson