Dynamic Loading of External HTML file Using Jquery

 

I’ve been playing around with the Jquery framework lately. I’m not a big JavaScript guy as my primary focus for the past few years now has been ActionScript/Flash/Flex. But I have to admit, Jquery (and I’m sure some of the other more robust JavaScript frameworks) is really nice.

Anyways, here’s how to load in an external html file into a div:

<script type=”text/javascript” src=”jquery-1.2.6.js”>
</script>
<script type=”text/javascript”>
$(document).ready(function(){
$(function () {
$(”#content”).load(”content.html”);
});
});
</script>

Here is the content.html file:

<html>
<head>
</head>
<body>
<h1>Here is my text file!</h1>
<p>Here is the second line of it!</p>
<p><strong>And the third!</strong></p>
</body>
</html>

View the result here.

Simple content management? Or is that an SEO no-no? I’m used to loading, parsing, and displaying XML via Flash. I’ll have to look into whether Jquery can do that too.

This entry was posted in HTML, Jquery and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

 

One Comment

  1. Posted October 15, 2008 at 12:11 pm | Permalink

    Easy and clean. Wouldn’t use to include any actual content that needs to be accessible and indexed by search engines but good for applications and interactive prototypes. Also ads could be inserted into the page after it has loaded to avoid troubles with slow ad-hosting services.

One Trackback

  1. By jQuery « Thoughts on… on December 17, 2008 at 1:58 am

    [...] http://elearninglive.com/wordpress/2008/09/dynamic-loading-of-external-html-file-using-jquery/ Possibly related posts: (automatically generated)BoinxTV 1.0 released today [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Subscribe without commenting