Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the state of cross-browser support for DOM Mutation Observers?

I googled but couldn't find an answer.

Is there a cross-browser compatibility matrix available for this feature?

In case anybody wants to know the answer, here it is: Mutation Observers vs Mutation Events/Browser Availability.

like image 959
Behrang Avatar asked Jun 10 '12 06:06

Behrang


People also ask

What is DOM mutation?

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.

How do you use mutation observer in Javascript?

This is done by setting the characterData property to true in the options object. Here's the code: let options = { characterData: true }, observer = new MutationObserver(mCallback); function mCallback(mutations) { for (let mutation of mutations) { if (mutation. type === 'characterData') { // Do something here... } } }


2 Answers

Ido Green provided the answer, but for clarity I will post relevant snippets of the linked docs here.

https://developer.mozilla.org/en-US/docs/DOM/Mutation_events

DOM Mutation Events are now deprecated.

The mutation events have been marked as deprecated in the DOM Events specification, as the API's design is flawed (see details in the "DOM Mutation Events Replacement: The Story So Far / Existing Points of Consensus" post to public-webapps).

The practical reasons to avoid the mutation events are performance issues and cross-browser support.

These are being replaced by DOM Mutation Observers.

https://developer.mozilla.org/en-US/docs/DOM/MutationObserver

Mutation Observers provides developers a way to react to changes in a DOM. It is designed as a replacement for Mutation Events defined in the DOM3 Events specification.

  • A brief overview
  • A more in-depth discussion
  • A screencast by Chromium developer Rafael Weinstein
  • The mutation summary library
  • The DOM4 specification which defines the MutationObserver interface
like image 182
Geuis Avatar answered Oct 14 '22 19:10

Geuis


This feature (DOM mutation) is working from Chrome 18. You can see more details here: http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers

In case you wish to check 'any' HTML5 feature and the browsers that support it: http://caniuse.com/ is the place. Other great source is: http://html5please.com/

like image 36
Ido Green Avatar answered Oct 14 '22 20:10

Ido Green