Loading content with jQuery
Tags: jQuery
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