目录
lastElementChild和lastChild:获取最后一个子节点
nextElementSibling和nextSibling:获取下一个兄弟节点
【兼容性封装】nextElementSibling和nextSibling
previousElementSibling和previousSibling:下一个兄弟节点
非 VIP 用户可前往公众号“前端基地”进行免费阅读,文章链接如下:
lastElementChild和lastChild:获取最后一个子节点
在 HTML DOM 操作中,lastElementChild 和 lastChild 分别用于获取元素的最后一个子元素节点和最后一个子节点。其使用规则与 firstElementChild 和 firstChild 类似。firstElementChild 和 firstChild 用于获取第一个子元素节点和第一个子节点,具体规则可参考:《13DOM 节点操作通关秘籍!父子节点与兼容性封装全解析》
同样,lastElementChild 和 lastChild 的兼容性封装方法也与 firstElementChild 和 firstChild 的兼容性封装类似。若你想了解具体的兼容性封装实现,可查看《13DOM 节点操作通关秘籍!父子节点与兼容性封装全解析》。