javascript-tutorial / javascript-tutorial/en.javascript.info
Incorrect usage of nextSibling and previousSibling
还没有人认领这个 Issue。
- 主要语言
- HTML
- 星标
- 25.5k
- 派生
- 4k
- PR 合并指标
- 30 天内没有已合并 PR
描述
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!
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的文档 URL 中的 Walking the DOM 页面开始,具体查看“Siblings and the parent”部分以及其中 nextSibling 和 previousSibling 的示例。检查这些示例是否正确考虑了文本节点,并更新文字或代码,使预期结果清晰明确。完成的标准是:示例不再暗示这些属性总是返回 HTMLBodyElement 或 HTMLHeadElement。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 50/100