NodeList 和 HTMLCollection 幾乎相同。
- getElementsByClassName() 有些瀏覽器回傳 NodeList,有些回傳 HTMLCollection
- childNodes 回傳 NodeList
- querySelectorAll() 大部分瀏覽器回傳 NodeList
NodeList和HTMLCollection的差別
- HTMLCollection 可以用 name / index / id 來搜尋;NodeList 只能用 index
- NodeList可以包含 attributes nodes 和 text nodes;HTMLCollection不行
HTMLCollection 不是陣列,不能用陣列的方法(methods)
source code
沒有留言:
張貼留言