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