Sunday, April 8, 2012

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 inserted. I was wondering if there's a DOM mutation event that I can add a listener for to know when the div has been inserted. I know I can use some kind of timer to periodically check for the div but I don't really like the overhead that this would impose.



Source: Tips4all

2 comments:

  1. There are some deprecated DOM mutation events, such as DOMNodeInserted and DOMNodeInsertedIntoDocument that still work for me in Chrome 14 and IE9.

    See an example at http://jsfiddle.net/Kai/WTJq6/

    See them all on the W3C draft at http://www.w3.org/TR/DOM-Level-3-Events/

    ReplyDelete
  2. Not without a plugin, I believe, but I wouldn't be surprised if I'm wrong.

    My research has found a a few to choose from.

    Here's one: http://plugins.jquery.com/project/mutation-events

    Here's another: https://www.adaptavist.com/display/jQuery/Mutation+Events

    ReplyDelete