DOM Range clones are not immune to DOM changes

試著忘記壹切 提交于 2019-12-07 23:25:32

问题


I am making a clone of a DOM Range using cloneRange() function. If I then modify the original range object like this:

range.setStart(range.startContainer, 1);

The clone preserves the old startOffset as expected.

However, if I modify the DOM tree, then the clone's startOffset will also get affected. Is there an intentional internal wiring between the DOM tree and all ranges that are associated with it (clones included)?

JS Fiddle Example


回答1:


Yes, there is. What happens to ranges under DOM mutation is specified in the DOM Level 2 Range specification. The more recent DOM4 Range specification specifies this under the mutation algorithms section (thanks to RobG for pointing that out).



来源:https://stackoverflow.com/questions/11404787/dom-range-clones-are-not-immune-to-dom-changes

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