You can put the script into a separate file, then use $.getScript
to load and run it.
Example:
$.getScript("test.js", function(){
alert("Running test.js");
});
Can someone please let me know how you would go about dynamically adding a <script> tag into the browser after page load, ideally via jQuery? javascript ...
Yes, use getScript instead of document.write - it will even allow for a callback once the file loads. You might want to check if TinyMCE is defined, though, ...
We can still do what we want with vanilla javascript. But if you are like me and using vanilla JS for DOM manipulations tires quickly, you could just decide it ...
Dynamic loading · Create a script element. · Set the src , async , and type attributes. · Append the script element to the body. · Check if the file loaded or not ...
js-example-tags").select2({ tags: true });. Note that when tagging is enabled the user can select from the pre-existing options or create ...