2013-07-23 94 views
0

如果我運行下面這樣確定的.class名。但我需要做類似下面:使用DOMNodeInserted

$(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 
}); 

千恩萬謝

回答

3

你可以只檢查.new長度,如下處理:

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

看到這個jsFiddle Demo

2

試試這個:

$(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 
    } 
});