0

I got output like below, how to append whole into the head tag using JavaScript?

<meta name="generator" content="Joomla! - Open Source Content Management" />
<title></title>
<link rel="stylesheet" href="templates/css/template.css" />
<link rel="stylesheet" href="templates/css/templatee.css" />
<style type="text/css">
    <![CDATA[
        BODY {background: #00ff00;color: rgb(0,0,255);}
    ]]>
</style>

7
  • Notice, that appending some meta tags after the head has been parsed is not useful, they are simply ignored. Commented Oct 5, 2014 at 17:04
  • I need all into head tag Commented Oct 5, 2014 at 17:09
  • Where is this output you got coming from? Commented Oct 5, 2014 at 17:12
  • The title of your question says you're appending a script tag, but your example contains no script tag. Commented Oct 5, 2014 at 17:14
  • head is guaranteed to be loaded and parsed before body, forking head afterwards breaks the default behavior. So, basicly you shouldn't do this. If you need dynamic head, create it on server-side. Rather this sounds like an XY-problem, what is the actual purpose of re-building the head? Commented Oct 5, 2014 at 17:21

1 Answer 1

1

You can try this:

document.querySelector('head').innerHTML = "insert your code here" 
Sign up to request clarification or add additional context in comments.

2 Comments

Not working. I hava all in text which contain may be link,script,title,meta tag, i cound not append all into head tag
Why not just document.head? Anyway, this will obliterate whatever content the head element used to contain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.