-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
Description
I encountered an error when learning about DOM navigation, in the Walking the DOM, under the Siblings and the parent using nextSibling and previousSibling. These properties return the next and previous node, which is the text node.
// parent of <body> is <html>
alert(document.body.parentNode === document.documentElement); // true
// after <head> goes <body>
alert(document.head.nextSibling); // Might not be HTMLBodyElement due to text nodes
// before <body> goes <head>
alert(document.body.previousSibling); // Might not be HTMLHeadElement due to text nodesIf you look at the alert displayed. The nextSibling and previousSibling may not return the expected HTMLBodyElement and HTMLHeadElement due to the presence of a text node.
Please consider updating, or correcting the examples.
Thank you!
Metadata
Metadata
Assignees
Labels
No labels