Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect usage of nextSibling and previousSibling #3771

Open
Disney-Banje opened this issue Oct 20, 2024 · 0 comments
Open

Incorrect usage of nextSibling and previousSibling #3771

Disney-Banje opened this issue Oct 20, 2024 · 0 comments

Comments

@Disney-Banje
Copy link

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 nodes

If 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant