mutation-observers

Webkit Mutation Observer callback not triggered when select box attribute's change

守給你的承諾、 提交于 2021-02-06 15:25:40
问题 I am trying to monitor changes to select box (or nested option elements) with new Mutation Observer functionality. However, only "setAttribute" is triggering mutation observer's callback for me. Here's the code I am using: ~function(doc, $) { var select = $('select'); // http://www.w3.org/TR/dom/#mutation-observers var observer = new WebKitMutationObserver(function(mutations) { alert(mutations.length + " mutations happened"); }); observer.observe(select, { // monitor descendant elements –

Webkit Mutation Observer callback not triggered when select box attribute's change

痴心易碎 提交于 2021-02-06 15:24:20
问题 I am trying to monitor changes to select box (or nested option elements) with new Mutation Observer functionality. However, only "setAttribute" is triggering mutation observer's callback for me. Here's the code I am using: ~function(doc, $) { var select = $('select'); // http://www.w3.org/TR/dom/#mutation-observers var observer = new WebKitMutationObserver(function(mutations) { alert(mutations.length + " mutations happened"); }); observer.observe(select, { // monitor descendant elements –

Performance of MutationObserver and ways to improve it

时光毁灭记忆、已成空白 提交于 2021-01-29 17:22:39
问题 I have some questions regarding MutationObserver and ways to improve it. From that answer: Use debounce or a similar technique e.g. accumulate mutations in an outer array and schedule a run via setTimeout / requestIdleCallback / requestAnimationFrame: const queue = []; const mo = new MutationObserver(mutations => { if (!queue.length) requestAnimationFrame(process); queue.push(mutations); }); function process() { for (const mutations of queue) { // .......... } queue.length = 0; } Is it

How do I make a MutationObserver work more then once?

一个人想着一个人 提交于 2021-01-28 09:29:53
问题 I using to a MutationObserver so I can have a div react to changes. When it changes the changes to displayed in the div directly under, however it only runs once. If I type something it to div the input div, only the first character is displayed. I found this on the MDN "Adding an observer to an element is just like addEventListener, if you observe the element multiple times it does not make a difference. Meaning if you observe an element twice, the observe callback does not fire twice, nor

What is the new equivalent of DOMNodeInserted?

ⅰ亾dé卋堺 提交于 2021-01-27 12:25:34
问题 The DOMNodeInserted event has been deprecated and all Mutation Events have been replaced with mutation observers. But, within mutation observers there are only config options for watching mutations to the nodes attributes, content, and children. Nothing about a mutation to it's placement in the DOM tree. There is one "solution" I can think of which is to observe everything from document.body down searching for the one mutation which is my target node being added, but that's a pretty awful way

Confused About MutationObserver

六眼飞鱼酱① 提交于 2021-01-20 20:08:32
问题 So I have been rattling my brain about using the MutationObserver and I haven't made any progress. I've read about it on the W3C site and in the MDN. When reading it in the MDN, everything made sense until the example. // select the target node var target = document.querySelector('#some-id'); // create an observer instance var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { console.log(mutation.type); }); }); // configuration of the observer: var

Confused About MutationObserver

杀马特。学长 韩版系。学妹 提交于 2021-01-20 19:56:26
问题 So I have been rattling my brain about using the MutationObserver and I haven't made any progress. I've read about it on the W3C site and in the MDN. When reading it in the MDN, everything made sense until the example. // select the target node var target = document.querySelector('#some-id'); // create an observer instance var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { console.log(mutation.type); }); }); // configuration of the observer: var

Can mutations observer be used to observe the addition and removal of a single node?

冷暖自知 提交于 2021-01-07 02:51:21
问题 I want to observe a single node for being added to the page. I do not want to get any notifications about any other mutations. I have no way of knowing where on the page the node will be appended. Is this possible? As far as I can tell, it's only possible to observe the child list of a parent element: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserverInit 回答1: No, it is not possible. Mutation observers only observe added child nodes of a target, not the adding or removing of a

Detect that given element has been removed from the DOM without sacrificing performance

一个人想着一个人 提交于 2020-08-04 18:19:54
问题 I've got these: const element = this.getElementById("victim") function releaseKraken(targetElement) {} I want the function to be called when element is removed from DOM. I can imagine something like this: element.onRemove(() => releaseKraken(element)) I understand that I need MutationObserver , but all the documentation I found focuses on watching given element's children, whereas I need to watch the element itself. UPD: the question How to detect element being added/removed from dom element?