Question

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

Was it helpful?

Solution

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

OTHER TIPS

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
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top