How to include html text from another file into an HTML5 page

Posted on Updated on

I have heard about objects, embeds, and even iframes for this purpose. In these options I had formatting issues with the main page style not being applied. Thus, I preferred jQuery and the <article> tag.

So to keep it simple, assign an ID to your article tag,



and load the page using jquery for the article mycustomhtml


$(“#mycustomhtml).load(“customhtml.txt”, function (response, status, xhr) {

if (status == “error”) {

var msg = “Error: “;

alert(msg + xhr.status + ” “ + xhr.statusText);



< /script>

This is as simple as it gets.

I would like to thank Shakeel Abdul Rehman for his help in this snippet.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s