O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading HTML Data into Page Elements

$("#content").load("new.html");

A great way to add dynamic data to a web page is to have the web server deliver the data already formatted as HTML. Then, using the jQuery .load() AJAX method, you can load the data directly into an element.

The .load() AJAX method can be called from any jQuery object and performs an AJAX get request in the background, formats the response, and injects it as the innerHTML of the element. For example:

$("#content").load("new.html");

The following code shows an example of using the .load() method to load lorem ipsum article data from the web server into an existing <div> container. Figure 13.4 illustrates loading ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required