Mr Portman

School website critiques, articles on education and some random cod

Loading content with jQuery

Tags:

Date: 7th May, 2010

Use the jQuery load() function as follows:

$(‘#nameofcontainertofill’).load(‘content.html’);

…and if you only want the part of that content, perhaps only one div:

$(‘#nameofcontainertofill’).load(‘content.html #wanthisbit’);

Getting this to work with a link, first disable the link (if you want to):

$(“#listoflinks li a”).click(function() { return false; });

…then get the links to load the content:

$(“li#specificlink a”).click(function(){
$(‘#nameofcontainertofill’).empty();
$(‘#nameofcontainertofill’).load(‘content.html #wanthisbit’);
});

* Note the use of empty() to clear the old content before loading the new content

August 2010

July 2010

June 2010

May 2010

April 2010

February 2010

January 2010

December 2009

November 2009

October 2009

September 2009