0

I have a html file which is just my footer. How can I use this in another file? Do I need to use php?

I'm looking for something like this:

<section>
<p>site content</p>
</section>

<?php footer html from a different file goes here ?>

Will this include the styling and javascript that is referenced in the head of the file i'm getting the html from?

Thanks!

Ed AT
  • 1

2 Answers2

-1

Now, when you visit index.html, you should be able to click the link tags.

IN HTML

<html>
<head>
<title></title>
<script
    src="https://code.jquery.com/jquery-3.3.1.js"
    crossorigin="anonymous">
</script>
<script> 
$(function(){
  $("#header").load("header.html"); 
  $("#footer").load("footer.html"); 
});
</script> 
</head>
<body>
<div id="header"></div>
<!--Remaining section-->
<div id="footer"></div>
</body>
</html>

IN PHP

<html>
<head>
<title></title>
</head>
<body>
<?php include('header.php'); ?>
<!--Remaining section-->
<?php include('footer.php'); ?>
</body>
</html>
Ravi Chauhan
  • 1,409
  • 13
  • 26
-1

If you are using PHP you can require you can find more about it here.
If you don't want to use PHP you will have to use AJAX.
Example :

$.ajax({
    url: "yourHTMLFile.html",
    dataType: "html",
    success: function(data) {
     $("body").html(data);
    }
});​
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
SIL0RAK
  • 7
  • 2
  • 4