Dynamically load jquery in plain javascript
<p>I am taking a page that does not have jquery referenced in the dom. I need to use some of the jquery functionality, so i figured the best bet is to inject jquery into the existing dom. I got the function idea from <a href="https://stackoverflow.com/questions/10113366/load-jquery-with-javascript-and-use-jquery">Load jQuery with Javascript and use jQuery</a> and  <a href="https://stackoverflow.com/questions/25442462/how-to-include-jquery-dynamically-in-any-website-using-pure-javascript">How to include jQuery dynamically in any website using pure javascript</a> ....none of these solutions seem to work for me. I am still getting an error not recognizing the jquery selector. </p>

<pre><code>(function() {
    function getScript(url, success) {
        var script = document.createElement('script');
        script.src = url;
        var head = document.getElementsByTagName('head')[0],
            done = false;
        // Attach handlers for all browsers
        script.onload = script.onreadystatechange = function() {
          if (!done &amp;&amp; (!this.readyState
               || this.readyState == 'loaded'
               || this.readyState == 'complete')) {
            done = true;
            success();
            script.onload = script.onreadystatechange = null;
            head.removeChild(script);
          }
        };
        head.appendChild(script);
    }
    getScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js',function() {
        // Yay jQuery is ready \o/
    });                         


    cards = $('div:first');
    $('body').empty().append(cards);

    // Delete first and second child divs

    first = $('div:first div:first');
    $('div:first div:first').css('position', '').css('left', '').css('z-index', '').css('height', '250px').remove();

    second = $('div:first div:first');
    $('div:first div:first').css('position', 'relative').css('left', '').css('z-index', '').remove();

    $('body').empty().append(first).append(second);
    })();
</code></pre>