DOM 节点类型及属性
生活随笔
收集整理的這篇文章主要介紹了
DOM 节点类型及属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、節點類型
| #document (文檔節點) | 9 | null |
| 大寫標簽名 (元素節點) | 1 | null |
| #text (文本節點 ) | 3 | 文本內容 |
| #comment (注釋節點) | 8 | 注釋的內容 |
二、獲取節點的方式
childNodes ? 獲取所有子節點
document.body.childNodeschildren ? 獲取所有元素子節點
document.body.childrenparentNode ? 獲取當前節點的父節點
document.body.parentNodepreviousSibling ? 獲取當前節點的上一個兄弟節點
document.body.previousSiblingperviousElementSibling ? 獲取當前節點的上一個兄弟元素節點
document.body.perviousElementSiblingnextSibling ? 獲取當前節點的下一個兄弟節點
document.body.nextSiblingnextElementSibling ? 獲取當前節點的下一個兄弟元素節點
document.body.nextElementSiblingfirstChild ? 獲取第一個子節點
document.body.nextElementSiblingfirstElementChild ? 獲取第一個元素子節點
document.body.firstElementChildlastChild ? 獲取最后一個子節點
document.body.lastChildlastElementChild ? 獲取最后一個元素子節點
document.body.lastElementChildoffsetParent ? 獲取定位父節點,默認默認以 body 標簽為定位父節點,如果為 fixed ,結果為 null
document.body.offsetParent <style>p {position: relative}span {position: fixed} </style> <body><div><span></span><p><a href="http://www.baidu.com">百度一下</a></p></div> </body> <script>const div = document.querySelector('div');const span = document.querySelector('span');const a = document.querySelector('a');console.log(div.offsetParent); // bodyconsole.log(span.offsetParent); // null --> 固定定位的父級不知道用什么表示,所以就是nullconsole.log(a.offsetParent); // p --> 因為a的父級p加了定位 </script>總結
以上是生活随笔為你收集整理的DOM 节点类型及属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于MFC串口编程和曲线图绘制(visu
- 下一篇: VS2010MFC - TeeChart