Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if browser supports MutationObserver

How does one write an if clause that would check to see if MutationObserver is supported?

like image 327
basickarl Avatar asked Jan 16 '16 16:01

basickarl


People also ask

Is MutationObserver supported?

Mutation Observer on Android Browser is fully supported on 4.4-103, partially supported on None of the versions, and not supported on 2.3-4 Android Browser versions.

How do you observe DOM changes?

One way to watch for DOM changes in our JavaScript web app is to use the MutationObserver constructor. })(); to create the MutationObserver instance with a loop to append child elements to the body within the async function. We insert a new p element after 1 second 5 times.

What is MutationObserver in JavaScript?

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.

How does mutation observer 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.


1 Answers

Try using in operator

The in operator returns true if the specified property is in the specified object.

Syntax

prop in objectName

Parameters

prop

A string or symbol representing a property name or array index (non-symbols will be coerced to strings).

objectName

Name of an object.

if ("MutationObserver" in window) {
  // do stuff
}
like image 82
guest271314 Avatar answered Oct 10 '22 13:10

guest271314