MutationRecord

每个 MutationRecord 都代表一个独立的 DOM 变化,在每次随 DOM 变化调用 MutationObserver 的回调函数时,一个相应的 MutationRecord 会被作为参数,传递给回调函数。

属性

属性 类型 描述
MutationRecord.type String 如果是属性变化,则返回 "attributes"
如果是 characterData 节点变化,则返回 "characterData"
如果是子节点树 childList 变化,则返回 "childList"
MutationRecord.target Node 根据 MutationRecord.type,返回变化所影响的节点。
对于属性 attributes 变化,返回属性变化的节点。
对于 characterData 变化,返回 characterData 节点。
对于子节点树 childList 变化,返回子节点变化的节点。
MutationRecord.addedNodes NodeList 返回被添加的节点。
如果没有节点被添加,则该属性将是一个空的 NodeList
MutationRecord.removedNodes NodeList 返回被移除的节点。
如果没有节点被移除,则该属性将是一个空的 NodeList
MutationRecord.previousSibling Node 返回被添加或移除的节点之前的兄弟节点,或者 null
MutationRecord.nextSibling Node 返回被添加或移除的节点之后的兄弟节点,或者 null
MutationRecord.attributeName String 返回被修改的属性的属性名,或者 null
MutationRecord.attributeNamespace String 返回被修改属性的命名空间,或者 null
MutationRecord.oldValue String

返回值取决于 MutationRecord.type
对于属性 attributes 变化,返回变化之前的属性值。
对于 characterData 变化,返回变化之前的数据。
对于子节点树 childList 变化,返回 null

注意,如果要让这个属性起作用,在相应的 MutationObserverInit 参数的 MutationObserver observe 方法中,attributeOldValue 或者 characterDataOldValue 必须设置为 true

规范

规范 状态 备注
DOM
MutationRecord
Living Standard
DOM4
MutationRecord
Obsolete

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
MutationRecordChrome Full support YesEdge Full support ≤18Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
addedNodesChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
attributeNameChrome Full support YesEdge Full support ≤18Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
attributeNamespaceChrome Full support YesEdge Full support ≤18Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
nextSiblingChrome Full support YesEdge Full support ≤18Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
oldValueChrome Full support YesEdge Full support ≤18Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
previousSiblingChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
removedNodesChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
targetChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
typeChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown