in JavaScript? [duplicate]", "text": "<p>I need to use <code>appendChild()</code> or jQuey's <code>append()</code> to append some <code><script></code> tag stuff into the document. From what I can tell, this is getting stripped out. Anyone know how to do it?</p>", "answerCount": 2, "upvoteCount": 699, "dateCreated": "2022-10-17 18:58:17", "dateModified": "2022-10-20 06:58:18", "author": { "type": "Person", "name": "David" }, "acceptedAnswer": { "@type": "Answer", "text": "<pre class="prettyprint"><code>// Create the element\n\nvar script = document.createElement("script");\n\n// Add script content\n\nscript.innerHTML = "...";\n\n// Append\n\ndocument.head.appendChild(script);\n</code></pre>\n\n<p>Or</p>\n\n<pre class="prettyprint"><code>document.body.appendChild(script);\n</code></pre>", "upvoteCount": 293, "url": "https://exchangetuts.com/how-to-append-scriptscript-in-javascript-duplicate-1639495925246056#answer-1666292297999263", "dateCreated": "2022-10-19 18:58:17", "dateModified": "2022-10-20 06:58:17", "author": { "type": "Person", "name": "Dennis" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "<p>Try this: </p>\n\n<pre class="prettyprint"><code>var s = document.createElement("script");\ns.type = "text/javascript";\ns.src = "http://somedomain.com/somescript";\n$("head").append(s);\n</code></pre>\n\n<p>Note that the script will load and you can access the variables inside it, but you wouldn't see the actual <code><script></code> tag in the DOM.</p>", "upvoteCount": 167, "url": "https://exchangetuts.com/how-to-append-scriptscript-in-javascript-duplicate-1639495925246056#answer-1666292298004327", "dateCreated": "2022-10-18 18:58:18", "dateModified": "2022-10-20 06:58:18", "author": { "type": "Person", "name": "Sapan Diwakar" } } ] } }