I want to create a script tag by jQuery.
I use the following code:
$("<body>").append("<script></script>");
It doesn't work. What will you do to achieve it?
Step 1: Open the HTML file in which you want to add your jQuery with the help of CDN. Step 2: Add <script> tag between the head tag and the title tag which will specify the src attribute for adding your jQuery. Step 3: After that, you have to add the following path in the src attribute of the script tag.
We can include the jQuery CDN URL in the script tag and use jQuery in HTML. We can either write the jQuery in a separate . js file and include it in the HTML file or write the jQuery inside the script tag. First, go to the JQuery CDN website and choose the latest stable version of the jQuery.
You can write it in side the tag, where you would write the javascript usually. Show activity on this post. You can write it directly to the HTML doc inside <script> tags or link with <script src="javascript.
You should do it like so
var script=document.createElement('script'); script.type='text/javascript'; script.src=url; $("body").append(script);
To load from a url:
$("body").append($("<script />", { src: url }))
To load from existing source code:
$("body").append($("<script />", { html: code }))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With