Inserting HTML from a text file with jQuery

Loading HTML from a text file is a useful way to get a better performance with the jQuery's load() method. Given a simple text file that contains the following line:

<h1>Test</h1>

we can easily load its content into a target element with a simple jQuery statement:

$(document).ready(function() {
    
        $('#test').load('test.txt');
    
    
});

You can see that test here. By doing so, we avoid HTML parsing while retrieving a given resource.

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.