mutation-observers

Attach javascript/jquery event on dynamically created elements

喜夏-厌秋 提交于 2019-12-07 05:00:49
问题 I've seen a lot of different questions similar to this, but all of them generally targeted a specific selector. Please let me know if there is a duplicate somewhere and I've missed it. Take this scenario: You want to build a jquery plugin for a wordpress, drupal, or basically any site that uses third party functionality. Since you don't know ahead of time every specific event and selector you will need to target how would you add jquery/javascript functionality to elements that are created

MutationObserver characterData usage without childList

别来无恙 提交于 2019-12-07 02:35:19
问题 Up until recently I thought that childList : true on MutationObserver was to be used when child node is being added/removed e.g from <span id='mama-span'> </span> to <span id='mama-span'><span id='baby-span'></span></span> and characterData : true was to be used when text inside observed element chages e.t <span> </span> to <span> with some text </span> . It turns out that for text change to be observed one needs to add childList : true . Can anyone think of situation in which characterData

How to get a jquery onClick to fire the same time as ember click and before mutation observers fire?

佐手、 提交于 2019-12-06 14:21:35
问题 I have a situation like so: I have a button with an ember action that causes a route change, with corresponding DOM updates. This DOM is also being watched by a mutation observer. What I want to do is run some jquery code after the user clicks the button but before the mutation observers fire. However currently the mutation observer is always firing before the jquery onClick is fired. How can I achieve my desired order? Should I use a deferred promise in the observer? 来源: https:/

What is the order of MutationRecords received by MutationObservers?

风格不统一 提交于 2019-12-06 02:31:16
The code from react-measure takes advantage of the new MutationObservers present in current browsers. MSDN has this to say about it: Additionally, mutation observers are designed to record multiple changes before notifying your observer. They batch mutation records to avoid spamming your app with events. By contrast, mutation events are synchronous and interrupt normal code execution to notify your app of mutations. Despite the delayed notification model employed by mutation observers, your apps's observer is still guaranteed to receive (and have a chance to process) all the mutation records

MutationObserver and current/computed CSS styles

不打扰是莪最后的温柔 提交于 2019-12-05 22:59:23
问题 I'm using a MutationObserver to look for added images to a web page. As many images are displayed via the CSS background-image property, I'm checking the current/computed CSS style in addition to looking for img tags, for example... var hasBackgroundImage = function(node) { var nodeStyle = node.currentStyle || getComputedStyle(node, null); return ( nodeStyle && nodeStyle.backgroundImage && nodeStyle.backgroundImage != "none" ); }; However, it seems there is a delay between a node triggering a

Implementing MutationObserver in place of DOMSubtreeModified

心不动则不痛 提交于 2019-12-05 13:21:14
I have a select[multiple] which I have given a class custom-multiselect on my page for which I am catching the DOMSubtreeModified event as follows: HTML: <select class="custom-multiselect"></select> JQuery: $('.custom-multiselect').each(function (i, select) { var sel = this; adjustHeight(sel); //Custom function //Binding DOMSubtreeModified to catch if the select list gets modified by the user $(sel).on('DOMSubtreeModified', function () { adjustHeight(sel); }); //For Internet Explorer $(sel).on('propertychange', function () { adjustHeight(sel); }); }); This approach works flawlessly. I want to

Attach javascript/jquery event on dynamically created elements

白昼怎懂夜的黑 提交于 2019-12-05 11:11:49
I've seen a lot of different questions similar to this, but all of them generally targeted a specific selector. Please let me know if there is a duplicate somewhere and I've missed it. Take this scenario: You want to build a jquery plugin for a wordpress, drupal, or basically any site that uses third party functionality. Since you don't know ahead of time every specific event and selector you will need to target how would you add jquery/javascript functionality to elements that are created dynamically. Plus you don't know how the element is created (callback using ajax/php/etc). Example: I

MutationObserver characterData usage without childList

和自甴很熟 提交于 2019-12-05 08:16:18
Up until recently I thought that childList : true on MutationObserver was to be used when child node is being added/removed e.g from <span id='mama-span'> </span> to <span id='mama-span'><span id='baby-span'></span></span> and characterData : true was to be used when text inside observed element chages e.t <span> </span> to <span> with some text </span> . It turns out that for text change to be observed one needs to add childList : true . Can anyone think of situation in which characterData would be used without childList? What is it used for? You can observe a text node directly. In that case

Why doesn't MutationObserver code run on Chrome 30?

喜欢而已 提交于 2019-12-05 04:08:37
From http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers I got the following code: var insertedNodes = []; var observer = new WebKitMutationObserver(function(mutations) { alert('run'); mutations.forEach(function(mutation) { for (var i = 0; i < mutation.addedNodes.length; i++) insertedNodes.push(mutation.addedNodes[i]); }) }); observer.observe(document, { childList: true }); console.log(insertedNodes); var divElement = document.createElement('div'); divElement.innerHTML = 'div element'; document.querySelector('body').appendChild(divElement); jsFiddle: http:/

How to inject mutationobserver to puppeteer

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:53:05
问题 I want trace changed DOM like mutationobserver in headless chrome. So I learning puppeteer library, but don’t know how to use do that. It’s possible to trace DOM change in puppeteer?? thanks 回答1: Well,you can inject custom code to the browser. One way: await page.evaluate(() => { const observer = new MutationObserver( function() { // communicate with node through console.log method console.log('__mutation') } ) const config = { attributes: true, childList: true, characterData: true, subtree: