Articles → JQUERY → Add Global Header And Footer In HTML Using Jquery
Add Global Header And Footer In HTML Using Jquery
Software Requirement
- Visual studio 2005 (or above) is installed on your machine.
- Latest jQuery file i.e. jquery-latest.js (from the path http://code.jquery.com/jquery-latest.js) is downloaded on your system.
Prerequisite Knowledge
- Basics about HTML
- Basics about JQuery.
Create 2 HTML Pages
- Page1.htm
- Page2.htm
Click to Enlarge
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Page 1</title>
</head>
<body>
<div id="header"></div>
<div id="body">
<table style="width: 100%;">
<tr>
<td>Login Id</td>
<td>
<input type="text" />
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="password" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="Login" />
</td>
</tr>
</table>
</div>
<div id="footer"></div>
</body>
</html>
Click to Enlarge
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Page 2</title>
</head>
<body>
<div id="header"></div>
<div id="body">
<table style="width: 100%;">
<tr>
<td>Forgot password</td>
<td>
<input type="text" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="Send Password" />
</td>
</tr>
</table>
</div>
<div id="footer"></div>
</body>
</html>
Add A Method Jquery Method To Create Footer
function AddFooter() {
var footer = "";
footer = "<table style=\"height: 20px; width: 1203px\"><tr><td>© All rights reserved <a href=\"ContactUs.html\">Contact Us</a></td></tr></table>";
return footer;
}
Call Method In Both The HTML Files
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript" src="Script.js"></script>
<script type = "text/javascript">
$(document).ready(
function() {
$("#footer").html(AddFooter());
}
);
</script>
Output
Click to Enlarge
Click to Enlarge