via .innerHTML add JavaScript dynamically adds script tag with SRC ATTRIBUTE via innerHTML For example: var ban...">

<script src = "..."> </script> via .innerHTML add

JavaScript dynamically adds script tag with SRC ATTRIBUTE via innerHTML

For example:

var banner = '<script src="http://example.com/script.js"><\/script>'; document.getElementById("examplediv").innerHTML = banner; 

I see a script tag in a DIV with id = "examplediv", but script.js is not loading.

The variable banner can contain different data (HTML code), and I cannot use document.createElement ('script') ;, setAttribute, etc.

Without any libraries like jQuery.

How can I load a script file and execute its contents?

PS Excuse me for my English.

0
javascript dom innerhtml
source share

No one has answered this question yet.

See similar questions:

4829
How to include a javascript file in another javascript file?
191
Is it possible to insert scripts using innerHTML?
7
Passing script to innerHTML

or similar:

2414
How to find out which switch is selected using jQuery?
917
How to replace innerHTML div with jQuery?
440
Script Tag - async & defer
241
load and execute script order
191
Is it possible to insert scripts using innerHTML?
157
Dynamically load javascript file
78
How to dynamically insert <script> tag through jQuery after page loading?
one
How to insert script tag and execute response via src?
one
innerHTML javascript not working
one
How to dynamically ad div with

All Articles