mutation-events

Most efficient method of detecting/monitoring DOM changes?

混江龙づ霸主 提交于 2019-11-26 11:20:45
I need an efficient mechanism for detecting changes to the DOM. Preferably cross-browser, but if there's any efficient means which are not cross browser, I can implement these with a fail-safe cross browser method. In particular, I need to detect changes that would affect the text on a page, so any new, removed or modified elements, or changes to inner text (innerHTML) would be required. I don't have control over the changes being made (they could be due to 3rd party javascript includes, etc), so it can't be approached from this angle - I need to "monitor" for changes somehow. Currently I've

How to change the HTML content as it's loading on the page

為{幸葍}努か 提交于 2019-11-26 07:48:57
问题 I do A/B Testing on our site and I do most of my work is in a JS file that is loaded at the top of the page before anything else is rendered but after jQuery has loaded which comes in handy at times. Taking a very simple example of changing an H1 tag, I would normally inject a style in the head to set the H1 opacity to 0 and then on DOMContentLoaded, I would manipulate the H1 contents and then set the opacity to 1. The reason for this is to avoid a flash of the old content before the change

DOM Mutation event in JQuery or vanilla Javascript

坚强是说给别人听的谎言 提交于 2019-11-26 06:35:41
问题 Are there any DOM mutation events in JQuery or in vanilla Javascript that fire cross browser? To clarify, say I have a script on my page which inserts a div into the body. I don\'t have access to the script and I don\'t know when the div has been inserted. I was wondering if there\'s a DOM mutation event that I can add a listener for, to know when an element has been inserted. I know I can use a timer to periodically check for the insertion but, I don\'t really like the overhead that this

is there an alternative to DOMAttrModified that will work in webkit

岁酱吖の 提交于 2019-11-26 06:06:00
问题 I need to leverage this DOM event. IE has onpropertychange, which does what I need it to do also. Webkit doesn\'t seem to support this event, however. Is there an alternative I could use? 回答1: Although Chrome does not dispatch DOMAttrModified events, the more lightweighted mutation observers are supported since 2011 and these work for attribute changes, too. Here is an example for the document body: var element = document.body, bubbles = false; var observer = new WebKitMutationObserver

DOM mutation events replacement

五迷三道 提交于 2019-11-26 05:27:55
问题 Since DOM mutation is marked as deprecated by the w3c (see http://www.w3.org/TR/DOM-Level-3-Events/#events-mutationevents), is there an (fast) alternative way to detect attribute modification in the DOM ? 回答1: As far as I know there is no alternative (yet) so you are stuck with DOMAttrModified which is only supported in Firefox and Opera. In IE you have the onpropertychanged event but there is no way to get similar functionality in Chrome/Safari. There are a number of things you could do

Most efficient method of detecting/monitoring DOM changes?

我与影子孤独终老i 提交于 2019-11-26 02:20:50
问题 I need an efficient mechanism for detecting changes to the DOM. Preferably cross-browser, but if there\'s any efficient means which are not cross browser, I can implement these with a fail-safe cross browser method. In particular, I need to detect changes that would affect the text on a page, so any new, removed or modified elements, or changes to inner text (innerHTML) would be required. I don\'t have control over the changes being made (they could be due to 3rd party javascript includes,

Detect changes in the DOM

隐身守侯 提交于 2019-11-25 22:16:05
问题 I want to execute a function when some div or input are added to the html. Is this possible? For example, a text input is added, then the function should be called. 回答1: 2015 update, new MutationObserver is supported by modern browsers: Chrome 18+, Firefox 14+, IE 11+, Safari 6+ If you need to support older ones, you may try to fall back to other approaches like the ones mentioned in this 5 (!) year old answer below. There be dragons. Enjoy :) Someone else is changing the document? Because if

Detect changes in the DOM

旧城冷巷雨未停 提交于 2019-11-25 21:41:38
问题 I want to execute a function when some div or input are added to the html. Is this possible? For example, a text input is added, then the function should be called. 回答1: 2015 update, new MutationObserver is supported by modern browsers: Chrome 18+, Firefox 14+, IE 11+, Safari 6+ If you need to support older ones, you may try to fall back to other approaches like the ones mentioned in this 5 (!) year old answer below. There be dragons. Enjoy :) Someone else is changing the document? Because if