Skip to main content
400 votes
12 answers
519k views

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's user avatar
  • 18.2k
173 votes
8 answers
211k views

I want a function of my choosing to run when a DOM element is added to the page. This is in the context of a browser extension, so the webpage runs independently of me and I cannot modify its source. ...
Kevin Burke's user avatar
  • 65.7k
139 votes
1 answer
69k views

I'm interested in using MutationObserver to detect if a certain HTML element is added anywhere in an HTML page. For example's sake, I'll say that I want to detect if any <li>'s are added ...
Jake Wilson's user avatar
  • 91.8k
70 votes
6 answers
142k views

I am creating a Chrome extension and trying to include a small text beside the SEND button of the gMail compose box. I am using a MutationObserver to know when the compose box window appears. I am ...
geet mehar's user avatar
65 votes
5 answers
26k views

Is there a way to detect when an element's getBoundingClientRect() rectangle has changed without actually calculating getBoundingClientRect()? Something like a "dirty flag"? Naively, I ...
micahscopes's user avatar
  • 1,154
53 votes
6 answers
63k views

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 ...
Graza's user avatar
  • 5,058
52 votes
4 answers
68k views

HTML5 includes a concept of "mutation observers" to monitor changes to the browser's DOM. Your observer callback will be passed data which looks a lot like DOM tree snippets. I don't know if they are ...
hippietrail's user avatar
  • 17.3k
52 votes
2 answers
35k views

I would like to use a MutationObserver object to observe changes to some of my DOM nodes. The docs give an example of creating a MutationObserver object and registering it on a target. // select ...
Luke's user avatar
  • 5,746
41 votes
3 answers
39k views

I am trying to make a function go off when a particular div is created. In the simplest of terms, I have something like this: <a href="" id="foo">Click me!</a> <script> $("#foo")....
Jimmy Ha's user avatar
  • 509
40 votes
1 answer
18k views

Is it possible to observer mutations on a DOM node that doesn't exist yet? Example: My app creates a div at some point: <div id="message" data-message-content="foo" data-message-type="bar" />. ...
Don P's user avatar
  • 64.3k
37 votes
4 answers
41k views

Consider the following code: var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; var observer = new MutationObserver(function(...
tic's user avatar
  • 4,209
36 votes
6 answers
43k views

I want to detect when text/value change in input field. Even if I change the value with js, I want to detect that changes. Here's what I've tried so far in demo in fiddle. HTML: <input type="...
while true's user avatar
35 votes
1 answer
32k views

I have a div that has additional classes added to it programmatically. How can I detect the class name change without using this setInterval implementation? setInterval(function() { var elem = ...
David's user avatar
  • 14.1k
32 votes
1 answer
27k views

I'm scratching my head as to why MutationObserver doesn't detect text changes done using textContent. HTML <div id="mainContainer"> <h1>Heading</h1> <p>Paragraph.</p&...
GTS Joe's user avatar
  • 4,252
32 votes
3 answers
33k views

I am using MutationObserver to detect when a specific class has been added to an element. const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { ...
sliptype's user avatar
  • 2,974

15 30 50 per page
1
2 3 4 5
45