Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript AJAX Basics (retiring) jQuery and AJAX Introducing jQuery

Steve Fielding
Steve Fielding
7,287 Points

Load depreciated

Hi, $(document).load("index.html"); has been depreciated. Does someone have an example of how to using $(document).on("load", function(){} to load a page . I keep seeing his script all over but haven't see anyone with an actual example.

1 Answer

Juan Martin
Juan Martin
14,335 Points

Hello Molayo,

I had the same concern a while ago but I've figured it out. What's being deprecated is the .load() function for document loading events (detecting when the document, or an specific element is loaded --> do something) and replaced with .on(), for example:

$("#someDiv").load(function() {
     // do something
});

// --- REPLACED WITH ---

$("#someDiv").on("load", function() {
     // do something
});

Loading an external page when something happens (event) is different because you're "loading data from the server and placing the returned HTML into the matched element", so in this case you're using an Ajax shorthand method, and of course, it's still available.

$( "#someDiv" ).load( "test.html" );

Here you can see the references of what I'm talking about:

(Document Loading) http://api.jquery.com/category/events/document-loading/

(Shorthand Methods -- Ajax) http://api.jquery.com/category/ajax/shorthand-methods/

Hope this helps :)