Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is MutationRecord.oldValue something I should be using?

I'm using the latest Google Chrome stable (19.0.1084.56 m) on Windows 7 and experimenting with Mutation observers for the first time. (The project is a user script for a third party website, the server of which I have no access to.)

So it happens that MutationRecord has a field oldValue:

record . oldValue

The return value depends on type. For "attributes", it is the value of the changed attribute before the change. For "characterData", it is the data of the changed node before the change. For "childList", it is null.

So I'm monitoring for changes to the characterData but when I get the MutationRecord the oldValue field is always null.

Should it be working, is there a possibility I've got something wrong, or is this feature just too bleeding edge to expect to work yet?

Is there somewhere I can find Google's documentation, bug report, feature request, etc that might declare whether this is implemented or when it might be?

like image 727
hippietrail Avatar asked Jul 02 '12 08:07

hippietrail


People also ask

When would you use a mutation observer?

MutationObserver can react to changes in DOM – attributes, text content and adding/removing elements. We can use it to track changes introduced by other parts of our code, as well as to integrate with third-party scripts. MutationObserver can track any changes.

How do mutation observers work?

MutationObserver is a Web API provided by modern browsers for detecting changes in the DOM. With this API one can listen to newly added or removed nodes, attribute changes or changes in the text content of text nodes.

What is window MutationObserver?

The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation Events feature, which was part of the DOM3 Events specification.

Does react use MutationObserver?

Instead of using the provided React state array of elements, we'll use the MutationObserver API to detect added elements and update the label accordingly. Update the dynamic label to count the number of fruits in the list.


1 Answers

Configure your observer with:

observer.observe(container, {
    attributeOldValue : true
});

Full API documentation: https://developer.mozilla.org/pt-BR/docs/Web/API/MutationObserver

like image 142
eduardo.lopes Avatar answered Oct 20 '22 12:10

eduardo.lopes