2 of 4 Apparently clicking a link is hard for some, so I've copy and pasted the code from plunkr into the question itself.

Namespacing jQuery/jQueryUi into markup that I don't control

I have a project that I've been trying to get just right for the past three months and it's still not quite there yet.

I'm injecting some jQuery and jQueryUi code into pages that I have no control over and I need to be able to "sandbox" my code away from anything that may or may not be there at DOM-ready, or at anytime there after...

I think I've got it, but PLEASE.. I know there's some edge cases and race conditions that I'm missing. Please fork this and tell me what I've missed.. Tired of spinning my wheels on this issue: http://plnkr.co/edit/iWJWLrpH4RpQwQUL0bYe?p=preview


<!DOCTYPE html>

    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
    <script type="text/javascript" src="//www.litmos.com/wp-includes/js/jquery/jquery.js?ver=1.11.0"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

    <h1>Loading multiple versions of jQuery!</h1>
    <script type="text/javascript">
        var $h2 = $('<h2>').append('Original jQuery: ' + $.fn.jquery + ' | Original ui: ' + $.ui.version);
    <div>Some other html</div>
  <!--// Code that is being "injected into the page" //-->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
        window.myJQuery = jQuery.noConflict(true);
    <script src="jquery-ui.js"></script>
    <script src="script.js"></script>
  <!--// End injection code //--> 
    <script type="text/javascript">
        var $h2 = $('<h2>').append('Original jQuery: ' + $.fn.jquery + ' | Original ui: ' + $.ui.version + ' | After namespacing');
            .toggle( "highlight" );
        }, 2000);



;(function($, jQuery){
  var $h2 = $('<h2 class="namespaced">').append('Namespaced $: ' + $.fn.jquery + ' | $.ui: ' + $.ui.version);
  var $jh2 = $('<h2 class="namespaced">').append('Namespaced jQuery: ' + jQuery.fn.jquery + ' | jQuery.ui: ' + jQuery.ui.version);
  //Verify that jQueryUi works on OUR version of jQuery:
})(myJQuery, myJQuery);