I want to add DOM element to head section of HTML. jQuery does not allow adding DOM element script to the head section and they execute instead, Reference.
I want to add script
tags and write a script within <head>
section.
var script = '<script type="text/javascript"> //function </script>' $('head').append(script);
Something like this with functions. I tried jQuery and javascript\, but it does not work.
Please tell me how to add and write script
to head by jQuery or javascript.
I tired the javascript to add DOM element, but it does not work with .innerHTML()
to write to head. I am using jQuery 2.0.3 and jQuery UI 1.10.3.
I want to add base64 encoded script to head section. I use base64 decoder js like this to decode the javascript and then put on the head section.
//Edited
It will be
$.getScript('base64.js'); var encoded = "YWxlcnQoImhpIik7DQo="; //More text var decoded = decodeString(encoded); var script = '<script type="text/javascript">' +decoded + '</script>'; $('head').append(script);
To fit an encoded script and the addition in one javascript file. I want to use base64.js
or some other decoder javascript files for browsers does not accept atob()
.
To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.
JavaScript in <head> or <body> You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
JavaScript in body or head: Scripts can be placed inside the body or the head section of an HTML page or inside both head and body. JavaScript in head: A JavaScript function is placed inside the head section of an HTML page and the function is invoked when a button is clicked.
try this
var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'url'; document.head.appendChild(script);
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