0

Why doesn't this code work in IE? Please help fix it:

jQuery('body').live('DOMNodeInserted',function(e){
    var parent = jQuery(e.target).parent();
    parent.find("a").css('color','#AA62C6');
    parent.find('a').removeAttr('onmousedown');
});
000
  • 26,951
  • 10
  • 71
  • 101
AkiraYamaokaNC
  • 350
  • 2
  • 6
  • 20

2 Answers2

2

This event is not supported in IE. This is added to IE9 but seems to be buggy in the implementation.

A solution will be to handle the dom manipulation at the base(The method which is changing the dom) level.

function update(){
    //do some dom manipulation
    $(window).trigger('customupdatedom', parent);
}
$(window).on('customupdatedom', function(e, parent){
    //handle dom change
})

You can also read the following
DOMNodeInserted equivalent in IE?
DOMNodeInserted event

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

Use onreadystatechange for IE:

var parent;

if (!!document.addEventListener)
  {
  jQuery('body').live('DOMNodeInserted',function(e){
    parent = jQuery(e.target).parent();
    parent.find("a").css('color','#AA62C6');
    parent.find('a').removeAttr('onmousedown');
    });
  }
else
  {
  jQuery("body").get(0).addBehavior("foo.htc");
  jQuery('body').get(0).attachEvent('onreadystatechange',function(e){
    parent = jQuery(e.target).parent();
    parent.find("a").css('color','#AA62C6');
    parent.find('a').removeAttr('onmousedown');
    });  
  }
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265