JQUERY .READY EVENT ON DYNAMIC CONTENT

Kate Smith

Total Post:24

Points:168
Posted by  Kate Smith
JQuery 
 1130  View(s)
Ratings:
Rate this:

I have a dynamic list loaded into a HTML 5 web app built using jquery mobile + (jquery and javascript).

I want to display a simple "loading..." image by placing a <div> on the page while the list is populated dynamically. Once the list is complete I need a event to fire to remove the "loading..." image. Is it possible to attach the .ready or .load events to a element of the dynamic list so I get a event to fire when the list has loaded?

Thanks for any advice, searching for existing answers on the .ready subject only provides results about document.ready use of the event.

  1. Hank Greenberg

    Post:12

    Points:84
    Re: jQuery .ready event on dynamic content

    Use the callback function.

    $(function() {
        $('#content').html('<div>loading...</div>');
        $('#content').load('http://mynewcontent.com/', function(data) {
            // optional: do more stuff here.. not needed since the content will already be replaced.
        });
    });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!