AkiraYamaokaNC
AkiraYamaokaNC

Reputation: 360

DOMNodeInserted in the IE

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');
});

Upvotes: 0

Views: 4474

Answers (2)

Paul Sweatte
Paul Sweatte

Reputation: 24617

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');
    });  
  }

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

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

Upvotes: 2

Related Questions