1

I have created this function in JQuery:

function OpenPage(pagename) {
    var page = pagename
    $('#LoadingDiv').show();
    $('.tabcontent').load(page);
    $("html, body").animate({ scrollTop: 0 }, "slow");
    window.onload = function () {
        $('#LoadingDiv').hide();
    }
}

it loads the selected page into a DIV using .load

before loading the page, its shows a div with a loading bar image, how can i hide this loading div once the page using .load has finished loading

i added window.onload at the end of my function but its not hiding the div

2 Answers 2

2

Use the complete callback of load( url [, data ] [, complete ] )

function OpenPage(pagename) {
    var page = pagename
    $('#LoadingDiv').show();
    $('.tabcontent').load(page, function(){
        /* new html exists now */
        $('#LoadingDiv').hide();
    });
    $("html, body").animate({ scrollTop: 0 }, "slow");    
}

Reference: load() Docs

Sign up to request clarification or add additional context in comments.

Comments

0

Use Callback Function of .load() function

A callback function that is executed when the request completes.

Change your code as

function OpenPage(pagename) {
    var page = pagename
    $('#LoadingDiv').show();
    $('.tabcontent').load(page,function () {
        $('#LoadingDiv').hide();
    });
    $("html, body").animate({ scrollTop: 0 }, "slow");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.