Skip to content

Instantly share code, notes, and snippets.

@maplemap
Last active May 26, 2022 08:46
Show Gist options
  • Save maplemap/0281fa27c82e9edd6658 to your computer and use it in GitHub Desktop.
Save maplemap/0281fa27c82e9edd6658 to your computer and use it in GitHub Desktop.
Add JS script and jQuery dynamically
<body onload="onload();">
<script>
function onLoad() {
var head = document.getElementsByTagName("head")[0];
var css = document.createElement("link");
css.href = "./css/bundle.css";
css.type = "text/css";
css.rel = "stylesheet";
css.async = true;
head.appendChild(css);
var jquery = document.createElement("script");
jquery.src = "./js/jquery.min.js";
jquery.type = "text/javascript";
head.appendChild(jquery);
jquery.onload = function () {
var js = document.createElement("script");
js.src = "./js/bundle.js";
js.type = "text/javascript";
head.appendChild(js);
js.onload = function () {
$(document).ready(function () {
//your code
});
};
}
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment