Friday, February 1, 2013

Using jQuery to include a supporting file

There are times when you'll want to include a file from your server in a page, but don't have access to server-side code like ASP's include directive.  For instance, you may be working in pure HTML, and want to include a navigation menu on every page without duplicating it each time.  You may be tempted to use an iframe for that, or render it with a javascript function full of document.write statements.  Both are options, and have their uses, but jQuery offers another solution: the .load() method.  It is very similar to the .get() function, except that it assumes a few defaults, and has an extra option for only inserting a certain part of the returned content.