My question regards the use of jQuery’s .load() method. The code below loads some content from a page on my site, into the current one.
$('a').click(function(event){
$('#result').load("mywebpage.html #report");
event.preventDefault();
});
This works well, but as I understand it, the .load() method as used above, actually returns mywebpage.html in it’s entirety, just to get the contents of div named #report.
If mywebpage.html was an especially large file, and I had a busy site, then I’d want to optimise this call, so that it just returned the contents of the #report div.
Is jQuery capable of doing this on a static html-only website?
NO
jQuery is, after all, javascript. The
.load()method will be AJAX-based. And AJAX can only fetch full files. Even if it could fetch partial files, it would still need to fetch the full file to _find out where the div is in the first place.If you had access to the server, you could make a PHP page using an XML parser that does this. If you only ever want to load that element, keep it in a separate html file. Otherwise, nope.