+ 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
8 Antworten
+ 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)
+ 5
Use arr[3] instead of 1
+ 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?
+ 2
Why don't use a query selector like document.querySelector("#header p").innerHTML = "New Name" and save some headache.
+ 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
+ 1
ODLNT
console.log([...arr])
That is it
+ 1
RDC it works now,thanks....but... I dont see any empty lines in the <div> ,..so I'm a bit confused
- 4
cuz your bad