Number of nodes returned in MutationRecord.addedNodes nodelist (mutationObserver)

百般思念 提交于 2019-12-11 00:44:02

问题


MutationRecord.addedNodes returns NodeList with nodes detected as added in my document. When I use obj.appendChild() method, mutationObserver detects it and returns this ONE node in MutationRecord.addedNodes as nodelist [node]. When I use .appendChild() in loop, mutationObserver fires as many times as the number of loops amounts.

I'm just wondering if there is any case when mutationOvserver will detect more than one node added simultaneously and fire ONCE and return those nodes in MutationRecord.addedNodes as ONE nodelist [node,node,node,...]?


回答1:


Judging by the spec one appendChild corresponds to a single-node addedNodes array.

addedNodes usually contains many nodes during the initial page load and, naturally, if many nodes were inserted by js code in one operation via insertAdjacentHTML, or document.write, or .innerHTML, or .outerHTML, or DocumentFragment with many nodes.



来源:https://stackoverflow.com/questions/38847779/number-of-nodes-returned-in-mutationrecord-addednodes-nodelist-mutationobserver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!