DOM API 下

遍历

DOM API 中提供了 NodeIterator 和 TreeWalker 来遍历树并且提供了过滤功能,但是为何我们再开发者不常见呢,是因为他们有些鸡肋,常用的遍历DOM可以使用递归或者Node的属性

Range

Range的api多用于富文本编辑或者底层框架,其他地方也不常用,因为用起来比较麻烦

Range API 表示一个 HTML 上的范围,这个范围是以文字为最小单位的,所以 Range 不一定包含完整的节点,它可能是 Text 节点中的一段,也可以是头尾两个 Text 的一部分加上中间的元素。

命名空间

最主要的场景是 SVG

创建元素和属性相关的 API 都有带命名空间的版本:

document

        createElementNS

        createAttributeNS

Element

        getAttributeNS

        setAttributeNS

        getAttributeNodeNS

        setAttributeNodeNS

        removeAttributeNS

        hasAttributeNS

        attributes.setNamedItemNS

        attributes.getNamedItemNS

        attributes.removeNamedItemNS

若要创建 Document 或者 Doctype,也必须要考虑命名空间问题。DOM 要求从 document.implementation 来创建。

document.implementation.createDocument

document.implementation.createDocumentType

除此之外,还提供了一个快捷方式

document.implementation.createHTMLDocument

此文章为4月Day12学习笔记,内容来源于极客时间《重学前端》

你可能感兴趣的:(前端,vue.js,javascript)