I was thinking there was no DOM listener so I implemented my own 'heavy' listener:
function CvHelper(stackApi) {
var that = this;
// check if room is finished loading
this.init = function() {
if ($('#loading').length) {
setTimeout(that.init, 1000);
} else {
console.log('Chatroom finished loading');
that.postListener();
}
}
}
(function() {
var stackApi = new StackApi();
var cvHelper = new CvHelper(stackApi);
cvHelper.init();
})();
I think this just sucks. So I did a search on here on SO and this question popped up. However the last comment on the accepted question states that it is deprecated.
$("#someDiv").bind("DOMSubtreeModified", function() {
alert("tree changed");
});
w3.org/TR/DOM-Level-3-Events/#event-type-DOMSubtreeModified says this event is deprecated, what would we use instead?
Is there a substition for it?
P.S. It only has to work on Chrome, because it is an Chrome extension.
If you take a look at:
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEvent
It states that, regarding DOMSubtreeModified, "It may be fired after a single modification to the document or, at the implementation's discretion, after multiple changes have occurred."
Therefore, if you use a different MutationEvent, say DOMNodeInserted, you may get a more deterministic firing of events (You'd just have to add an element to the node in that specific case).
See below:
This was tested in Chrome, btw.
Hope that helps...
UPDATE: Alternatively, you could add more than one event type in one function call. For example, adding four event handlers for DOMNodeInserted, DOMNodeRemoved, DOMAttrModified, DOMCharacterDataModified, then all of the handlers call a single handler.
UPDATE: I wrote a little script that does what I had just written in the previous update:
The Mutation Event is currently deprecated because of it's performance issue. Hence, Please use the Mutation Observer. I did the DOM changes listener in one of my project using Mutation Observer and it worked great! For your further implementation, these links will help you:
It looks like it's actually only deprecated in in the working draft of DOM Level 3 Events, which provides this note:
So if I understand correctly, the answer to the question "Is there a substitution yet?" is "no, not yet."