Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用DomainNodeInserted确定.class名称_Javascript_Jquery_Dom_Mutation Events - Fatal编程技术网

Javascript 使用DomainNodeInserted确定.class名称

Javascript 使用DomainNodeInserted确定.class名称,javascript,jquery,dom,mutation-events,Javascript,Jquery,Dom,Mutation Events,如果我在下面运行此操作: $(document).bind('DOMNodeInserted', function(){ $('.new', this).hide(); }); 它将正常运行,并将隐藏.new div。但我需要执行以下操作: $(document).bind('DOMNodeInserted', function(){ // if class .new exists // do something to the other

如果我在下面运行此操作:

$(document).bind('DOMNodeInserted', function(){

      $('.new', this).hide();
});
它将正常运行,并将隐藏.new div。但我需要执行以下操作:

$(document).bind('DOMNodeInserted', function(){

          // if class .new exists
          // do something to the other elements e.g (body, #div, h1, h2, etc) not to .new class
});
非常感谢

试试这个:

$(document).bind('DOMNodeInserted', function () {    
    if ($('.new').length) {
        // if class .new exists
        // do something to the other elements e.g (body, #div, h1, h2, etc) not to .new class
    }
});
试试这个:

$(document).bind('DOMNodeInserted', function () {    
    if ($('.new').length) {
        // if class .new exists
        // do something to the other elements e.g (body, #div, h1, h2, etc) not to .new class
    }
});

您只需检查
.new
的长度,并按如下方式进行处理:

$(document).bind('DOMNodeInserted', function(){
    if($('.new').length > 0)
    {
        $('body *').not('.new').hide();
    }
});

查看此

您只需检查
.new
的长度,并按如下方式进行处理:

$(document).bind('DOMNodeInserted', function(){
    if($('.new').length > 0)
    {
        $('body *').not('.new').hide();
    }
});
看到这个了吗