JSFiddle - React, Tailwind, and code Playground
HTML
<!-- uncomment the script below to see example of jQuery already being present on page -->
<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
-->
<div id="jqueryMessage"></div>
JavaScript
function getScript(success) {
var fm_j = document.createElement('script');
fm_j.type = 'text/javascript';
fm_j.src = '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js',
done = false;
// Attach handlers for all browsers
fm_j.onload = fm_j.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
// callback function provided as param
success();
};
};
document.getElementsByTagName('head')[0].appendChild(fm_j);
};
if(!window.jQuery) {
getScript(function() {doSomething(true)});
} else {
doSomething(false);
}
function doSomething(isDynamic) {
$(function() {
if(isDynamic) {
$('#jqueryMessage').text('jQuery has been loaded dynamically!');
} else {
$('#jqueryMessage').text('jQuery already loaded');
}
});
}