Search code examples
javascriptjqueryhtmllive

How to live check element inset html with jQuery.


I have some block with dinamicly parsing content. I need to change some style for it but if there is some html. My question: is there any possible to live check with jQuery that some element have html at specify moment and set some actions if it's for example empty? Thx for some information.

My code:

if ($('.degrees').live().html === ("")){
    $('.block').fadeOut('slow');
}

Solution

  • Try this:

    to detect divs that were empty and got their html changed:

    $('.degrees:empty').on('DOMSubtreeModified',function(){
        //...
    });
    

    to detect every html change

    $('.degrees').on('DOMSubtreeModified',function(){
        if($(this).is(':empty')) // check if it became empty ..
    });