Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial render in HTML/JavaScript

Tags:

I have some HTML files, and each one of them I want to partially render in another HTML file, for example header.html and footer.html in order to observe DRY concept.

HTML files should look like this:

<!--render header.html--> <div>     Content </div> <!--render footer.html--> 

How can I do that?

like image 360
Afshin Mehrabani Avatar asked Jul 22 '12 07:07

Afshin Mehrabani


1 Answers

If you're just using plain HTML and Javascript, you could include jQuery and use an AJAX request to load the contend of another HTML page in your main page.

Have a look at the jQuery 'load()' function here:

http://api.jquery.com/load/

Assuming your have the following html:

<div id="header"></div> <div id="content"></div> <div id="footer"></div> 

your usage would look something like this:

$('#header').load('header.html'); $('#footer').load('footer.html'); 
like image 158
dougajmcdonald Avatar answered Oct 01 '22 23:10

dougajmcdonald