How i can include a javascript file in other javascript?
Its frontend javascript.
I not want to include in html, i want like in nodeJS:
var jquery = require("jquery.js");
jquery.$("#c").style.color = "green";
I tried this:
const jqLink = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js';
/* I try this, what give me a error, with requireJS */
define([jqLink], function(jq){
return jq;
});
jq$("#c").style.color = "red";
<html><head><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js"></script>
</head>
<body><h1 id="h1tag">Im h1tag</h1>
</body>
PD: i tried this too:
Main.js :
window.addEventListener("DOMContentLoaded",main);
function main(){
scripts();
var e = new ES();
e.get("#ti").style.opacity = +true;
}
function scripts(){
var list = ["es.js"], script = document.createElement("script"),b = document.head, i=0,max = list.length;
for(;i<max;i++){
script.src = list[i];
b.appendChild(script);
}
}
ES.JS:
class ES{
constructor(){
}
get(symbol, e){
let d = document;
return symbol === "#" ? d.getElementById(e) : symbol === "." ? d.getElementsByClassName(e) : d.getElementsByTagName(e);
}
}