Search code examples
jqueryhead

Remove Head content and/or body tags found within parent page body


Because of my cms tool, I need to add a <head> and <body> to some include files on my site. For obvious reasons, I don't want the parent page to see the <head> region or <body> tags of the included page. The cms has a standard if, else rule I'm using on.ready to apply rules based on being logged in/out of the cms.

I'm wondering if there is a way with jquery, to within the parents body: (1) remove all <head> tags and all content within, and (2) remove <body> tags, but keep their content.

Any help would be appreciated. Thanks.


Solution

  • yes and it's called .load(). Many people seems to have problem with it, so you might have to study the question a little. But bascily, it allows you to load a docuemnt and return only a section of it..

    If you need help building the code let me know but this sould have all tha info you need. http://api.jquery.com/load/

    example show in the link

    $('#b').load('article.html #target');
    

    Basicly, i will read arctile.html to find the id #traget, and return this data in the #b element. Simple. ;)

    If on the other side, you want to remove from your CURRENT page, you can alternatively use the .remove() fucntioné

    To remove the head from you CURRENT page you simply have yo do

     $('head').remove();
    

    be aware that it will also remove the childs inside of it.