print script tags on a div with jquery


I would like to know how to print script tags in the html with jquery

asked by Josbert Hernandez 03.08.2016 в 02:06

3 answers


You can use the append () method to add it to the end of the content of an element, I'll assume that in your case the div has a id="miDiv" :


If you want to replace the text in the div, you can use html () or replaceWith () :

answered by 03.08.2016 в 02:34

Even if I do not answer the question I would like to provide a solution without using jQuery for those who might be interested.

It's as simple as creating a script tag with the createElement method and adding the src attribute with the path to your .js file via setAttribute . Then, just add it to the head of your document.

const scriptTag = document.createElement('script')
scriptTag.setAttribute('src', '')

A code somewhat more extensive than in the jQuery version but quite readable and equally efficient.

answered by 03.08.2016 в 08:13

With the .text function of jQuery you can send print html and javascript code.


Greetings ...

answered by 03.08.2016 в 16:43