PCA
PCA

Reputation: 1707

Loading a header footer seperatly from another file using jquery Load

I'm trying to add a header, footer and all the script files. Firstly i want to load all the script files which is in another file right next to the tag, How to do this using jquery.

Similar for the header and footer also i want to load separately from a different file.

Thanks

$(document).ready(function(){
    $("head title").load("../scriptincludes.html");
});

Here i'm trying to load a buch of scripts and css after the title tag, but what is happening is this is inserting within the title tag.

Upvotes: 1

Views: 2690

Answers (1)

Alkis Kalogeris
Alkis Kalogeris

Reputation: 17773

You are getting your result in your title tag because of your selector

$("head title")

You will have to put a proper target selector to achieve what you want. Let's assume the footer example. Place a div with an id #footer that is empty in your html file (the result file). On document ready you can call

$("#footer").load("../scriptincludes.html");

This is the same for the header too. For your script and link tags (js, css).

$("head").load("../scriptincludes.html");

If you have all your dependencies in one file then see this. In your load method you can put your file, but you can put a selector too like this

$('#footer').load('../scriptincludes.html #target');

Upvotes: 1

Related Questions