For your original version
If you want to dynamically include html content, here is a way to do it,
HTML
<link data-include="includes/header.html">
Js
$('link[data-include]').each(function(){ var el = $(this), template = $(this).data('include'); $.get(template, function(data){ $(el).replaceWith(data); }); });
Hope this helps!
Try
Now you can include any partial content that you need.
<!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>title</title> <meta name=viewport content="width=device-width, initial-scale=1"> <meta http-equiv=X-UA-Compatible content="IE=edge"> <link href=assets/css/elegant-icons.min.css rel=stylesheet type=text/css media="all"/> <link href=assets/css/bootstrap.css rel=stylesheet type=text/css media="all"/> <link href=assets/css/theme.css rel=stylesheet type=text/css media="all"/> <link rel=stylesheet type=text/css href="assets/css/style.css"/> </head> <body> <link data-include="header.html"> <div class=main-container> <section class="no-pad coming-soon fullscreen-element"> </section> </div> <script src=assets/js/jquery.min.js></script> <script src=assets/js/bootstrap.min.js></script> <script src=assets/js/smooth-scroll.min.js></script> <script src=assets/js/scripts.js></script> <script> $(function(){ $('link[data-include]').each(function(){ var el = $(this), template = $(this).data('include'); $.get(template, function(data){ $(el).replaceWith(data); }); }); }); </script> </body> </html>
source share