Test if jQuery is loaded.

Test if jQuery is loaded. If not, load it.

by Nirvanachain

HTML

<div id="test">
    <p>This is a test.</p>
</div>

JavaScript

if (typeof jQuery == 'undefined') {
    s = document.createElement("script");
    s.src = "//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
    if (s.addEventListener) {
        s.addEventListener("load", runScript, false);
    } else if (s.readyState) {
        s.onreadystatechange = runScript;
    }
    document.getElementsByTagName('head')[0].appendChild(s);
} else {
    runScript();
}

function runScript() {

    $('#test').css({
        'font-size':'50px', 
        'background-color':'blue',
        'color':'red'
    });

}