0

If i run this below:

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

      $('.new', this).hide();
});

it will run ok and it will hide the .new div. But i need to do something like the below:

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

many thanks

000
  • 26,951
  • 10
  • 71
  • 101
medzi
  • 407
  • 1
  • 8
  • 20

2 Answers2

3

You can just check the length of .new, and handle it as follows:

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

See this jsFiddle Demo

animuson
  • 53,861
  • 28
  • 137
  • 147
BenM
  • 52,573
  • 26
  • 113
  • 168
2

Try this:

$(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
    }
});
dfsq
  • 191,768
  • 25
  • 236
  • 258