DOMNodeInserted in the IE

橙三吉。 提交于 2020-01-24 00:55:07

问题


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

回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/15018590/domnodeinserted-in-the-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!