Questions tagged [mutation-events]

Mutation Events have been deprecated in favor of Mutation Observers.

Mutation Events provided a way to notify javascript of changes to the DOM. It didn't go so well: http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/0779.html

Mutation Events is not performant, and has many issues. Use instead.

67 questions
279
votes
8 answers

Detect changes in the DOM

I want to execute a function when some div or input are added to the html. Is this possible? For example, a text input is added, then the function should be called.
esafwan
  • 14,622
  • 30
  • 99
  • 154
48
votes
6 answers

Most efficient method of detecting/monitoring DOM changes?

I need an efficient mechanism for detecting changes to the DOM. Preferably cross-browser, but if there's any efficient means which are not cross browser, I can implement these with a fail-safe cross browser method. In particular, I need to detect…
Graza
  • 4,982
  • 6
  • 30
  • 37
42
votes
5 answers

Preferred way of modifying elements that have yet to be created (besides events)

There are a lot of questions about binding future manipulations to non-existent elements that all end up answered with live/delegate. I am wondering how to run an arbitrary callback (to add a class or trigger a plugin, for example) to all existing…
scragz
  • 6,572
  • 2
  • 21
  • 23
30
votes
5 answers

Alternative to DOMNodeInserted

DOMNodeInserted is known to make dynamic pages slow, MDN even recommends not using it altogether, but doesn't provide any alternatives. I'm not interested in the element inserted, I just need to know when some script modifies the DOM. Is there a…
Fábio
  • 3,003
  • 4
  • 31
  • 44
24
votes
6 answers

DOM Mutation event in JQuery or vanilla Javascript

Are there any DOM mutation events in JQuery or in vanilla Javascript that fire cross browser? To clarify, say I have a script on my page which inserts a div into the body. I don't have access to the script and I don't know when the div has been…
aziz punjani
  • 24,673
  • 9
  • 42
  • 56
21
votes
4 answers

DOM mutation events replacement

Since DOM mutation is marked as deprecated by the w3c (see http://www.w3.org/TR/DOM-Level-3-Events/#events-mutationevents), is there an (fast) alternative way to detect attribute modification in the DOM ?
Franck Freiburger
  • 21,662
  • 20
  • 60
  • 90
21
votes
5 answers

is there an alternative to DOMAttrModified that will work in webkit

I need to leverage this DOM event. IE has onpropertychange, which does what I need it to do also. Webkit doesn't seem to support this event, however. Is there an alternative I could use?
blockhead
  • 9,317
  • 2
  • 41
  • 65
19
votes
6 answers

DOMNodeInserted equivalent in IE?

Other than using a timer to count the number of elements over time and looking for changes, I can't think of a better way to simulate this event. Is there some sort of proprietary IE version of DOMNodeInserted? Thanks.
CPrimer
  • 623
  • 1
  • 6
  • 13
16
votes
4 answers

Listening to events of a contenteditable HTML element

I'm trying to figure out if there is any way to listen to events like focus or change of an HTML element with contenteditable attribute. I have this html markup:

Hello World

I've tried these without any…
Mohsen
  • 58,878
  • 30
  • 149
  • 175
14
votes
1 answer

Mutation Observer fails to detect element's dom removal

So, I thought this was going to be pretty straight forward, there used to be a DOMNodeRemoved event, but that's deprecated, instead, MutationObserver should be used, the thing is, it doesn't fire, even whith the appropiate configuration. According…
undefined
  • 3,461
  • 3
  • 21
  • 34
11
votes
2 answers

Using DOMSubtreeModified mutation event. in jQuery

I have used the following jQuery code on my page and everything works fine on chrome.But when I open up the respective page in firefox I get the Unresponsive Script Error. I know as per DOM3 specification the mutation events have been deprecated.…
jGupta
  • 2,175
  • 4
  • 21
  • 48
11
votes
1 answer

Detect added element to DOM with Mutation Observer

I'm adding some element to DOM after drag event. I need to detect this element and the moment when this element was added. I use Mutation Observer but something is wrong, the code: var targetNodes = $('.mvly'); var MutationObserver =…
Lukas
  • 6,464
  • 16
  • 61
  • 114
10
votes
2 answers

How do I play a sound when an element changes, like SO Chat does?

I want a sound to play when an element changes on a page. I know how to do this, but I can't get it to play only on the first change, and don't do it later, until the user focuses the window (tab) and blurs it again. My current code: var notif = new…
nyuszika7h
  • 12,020
  • 5
  • 40
  • 49
9
votes
2 answers

How to change the HTML content as it's loading on the page

I do A/B Testing on our site and I do most of my work is in a JS file that is loaded at the top of the page before anything else is rendered but after jQuery has loaded which comes in handy at times. Taking a very simple example of changing an H1…
9
votes
2 answers

Are DOM Mutation Observers slower than DOM Mutation Events?

The following code utilize DOM Mutation Event DOMNodeInserted to detect the existence of the body element and wrap its innerHTML into a wrapper.
Ian Y.
  • 2,329
  • 5
  • 33
  • 50
1
2 3 4 5