0

Hi I have two html documents for the sake of this question lets say these are index.html index2.html

I want to include all the lines of code inside the body tag from index2.html into a section in index.html is it possible to create that link using either HTML, JS or Jquery?

I do not want to duplicate the information inside the body tag multiple times for this reason I want to keep it in a separate file and just include it into multiple documents.

  • 7
    Possible duplicate of [Include another HTML file in a HTML file](https://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file) – BlueWater Oct 10 '18 at 11:11

1 Answers1

2

I have use the following code using jquery:

index1.html

<head> 
<script src="jquery.js"></script> 
<script> 
$(function(){
  $("#fromindex2").load("index2.html"); 
});
</script> 
</head> 
<body> 
      <div>Find index2.html below</div>
      <div id="fromindex2"></div>
</body> 

index2.html

<head>
<title>Page Title</title>
</head>
<body>
    <div>
        <h1>Hello I am from index2.html</h1>
    </div>
</body>
Nicky Prusty
  • 108
  • 1
  • 5
  • Hi thanks for this contribution! it did work indeed, although I did find a small framework on github called csi.min.js which also does the same thing so chose to proceed with that instead! thanks for your help though it is much appreciated. – shaminder galla Oct 10 '18 at 15:57