Search code examples
javascriptjquerydocument-readyready

Is there a NotReadyFunction in jQuery?


Is it possible to check if the document is not ready and execute a function periodically in jQuery?

Simply I would like to achieve something like :

$('document').isNotReady(function(){

    $('#divState').text('Still Loading');  
});

$('document').Ready(function(){

    $('#divState').text('Loaded');
});

Is there a built-in function in jQuery to achieve something like this?


Solution

  • You can just append the div at the top of the page with the loading text and when the document is ready change the text to loaded.

    Edit

    As @James pointed out, there is a problem with your selector. You are using divState as a tag selector, which won't be valid. Either you can use an id selector or a class selector in this case like

    $("#divState") or $(".divState")

    $(function(){
        $('#divState').text('Loaded');
    });