Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 :)