admin管理员组文章数量:1388160
Are there any practical ways to tell what part of the DOM was modified if you know that it will be modified?
I am writing a plugin that will be running along with javascript that i did not write. an event will be triggered before DOM is modified, and one event will be triggered after the modification. It is my job to decide what was changed. is this possible, and if so what is the least horrible way to do this?
Are there any practical ways to tell what part of the DOM was modified if you know that it will be modified?
I am writing a plugin that will be running along with javascript that i did not write. an event will be triggered before DOM is modified, and one event will be triggered after the modification. It is my job to decide what was changed. is this possible, and if so what is the least horrible way to do this?
Share Improve this question asked Mar 24, 2010 at 17:40 mkoryakmkoryak 58k64 gold badges203 silver badges262 bronze badges 4- this is an interesting question. No good way, nor a decent way. My first idea was to make a copy of all the dom objects in your "before change" event, and then in your "after change" event do a pare of the current dom objects with what you had made a copy of. This option is plausible if you have a known list of dom objects that could be changed, and you have a limited number of changes your expecting. Even if, this is an ugly solution and wouldn't remend it, but it is the first thing that came to mind. – Jay Commented Mar 24, 2010 at 17:49
- 1 You could write code that would pute an aggregate hash value of the sub-DOM at each node (based on whatever you care about in the DOM). It's important that the hash at each node be a function of the node and the subtree. Then you can track changes by checking first to see whether hash codes have changed. – Pointy Commented Mar 24, 2010 at 17:57
- In what structure would you hope to see the changed DOM? A string? An array of [new] top-level nodes? The top-most node whose subtree was modified? Please elaborate if possible. – Roatin Marth Commented Mar 24, 2010 at 19:50
- any format. i think the best would be a reference to a DOM node that is a parent of all modified DOM nodes (as low in the tree as possible) obviously you could just return document, but that wouldnt cut it. – mkoryak Commented Mar 24, 2010 at 21:49
5 Answers
Reset to default 5Depending on the browser support you need, you may be able to use DOM mutation events.
A possibility, if you know what aspect of the DOM elements are to be modified, is to store the value of that attribute in a .data() node for each element on page load, then pare after the script is run.
You could also do a hash of the page text (e.g. plete source string) and pare it (on change) to current hash.
With jquery you could trigger :animated filter to search the elements being animated, i don't know if you will have so much delay between these kind of events, but if main trigger on initial transform is triggered just when transformation is initiated you could try to catch :animated element and capture initial state before ending animation, then on end capture state and pare, its only a hint i don't have any demonstration or way to reproduce your working environment but i hope this guideline could give you a idea.
This is not possible in any practical manner
本文标签: javascriptis it possible to tell if DOM was modifiedand which partStack Overflow
版权声明:本文标题:javascript - is it possible to tell if DOM was modified, and which part? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744491758a2608775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论