12

Does anyone know the equivalent of this event in IE ?

Or may be a way around for this logic:

  document.addEventListener("DOMSubtreeModified", function (e) {
            if ($(e.target).hasClass("myclass")) {
                var getId= e.target.id;
            }
        }, false)

This works fine in FF, Chrome, Safari, IE 9 or higher.

Need an equivalent logic for IE8 and IE7

Ani
  • 4,473
  • 4
  • 26
  • 31
  • 1
    A short answer: an equivalent event doesn't exist in IE<9. However, changes to some elements/properties fire [`onpropertychange`](http://msdn.microsoft.com/en-us/library/ie/ms536956%28v=vs.85%29.aspx) event. – Teemu Nov 08 '13 at 22:24
  • you can always ping and trigger a custom event upon a change detection... getElemementsByTagName("*") will change it's .length property when elements are added or removed. – dandavis Nov 08 '13 at 22:28
  • I'd suggest writing your code in such a way that you don't depend on these kinds of events. – Kevin B Nov 08 '13 at 22:28
  • @dandavis That's what my 2nd option was. – Ani Nov 08 '13 at 22:59
  • @KevinB : I am implementing other option now, which won't need this event :( – Ani Nov 08 '13 at 23:00

1 Answers1

12

I had a similar problem (though I was using jQuery). I solved it by using the following

//chrome / ff
$(".myClass").on("DOMSubtreeModified", function() {
//do stuff
});     

//i.e.
$(".myClass").on("propertychange", function() {
//do same stuff 
});     

This can be further combined into a single event listener

$('.myClass').on('DOMSubtreeModified propertychange', function() {
    // do stuff
});
Soviut
  • 88,194
  • 49
  • 192
  • 260
JJones
  • 795
  • 6
  • 12