title: jQuery, do something after loading external files
body: <p>Ok, the point is having a bookmarklet load an external js that creates jquery, jquery-ui and a css file on the current web-page, with everything being done cross-domain. For some reason by the time the jquery code runs, dialog() function which is included in jquery-ui does not exist. My guess is that jquery is executing the code before the external scripts load.</p>
  
  <p>Please help!</p>
  
  <pre><code> function loadjscssfile(filename, filetype){
   if (filetype=="js"){ //if filename is a external JavaScript file
    var fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript")
    fileref.setAttribute("src", filename)
   }
   else if (filetype=="css"){ //if filename is an external CSS file
    var fileref=document.createElement("link")
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", filename)
   }
   if (typeof fileref!="undefined")
    document.getElementsByTagName("head")[0].appendChild(fileref)
  }
  
  loadjscssfile("http://localhost/js/jquery-1.3.2.min.js", "js") //dynamically load and add this .js file
  loadjscssfile("http://localhost/js/jquery-ui-1.7.2.custom.min.js", "js") //dynamically load "javascript.php" as a JavaScript file
  loadjscssfile("http://localhost/css/redmond/jquery-ui-1.7.2.custom.css", "css") //dynamically load and add this .css file
  
  $(document).ready(function() {
      var title = document.title;
      var location = document.location;
      var documentInfo = "url="+location+"&amp;title="+title;
  
  
      div = $("&lt;div id=dialog name=dialog&gt;").html("&lt;img src='http://localhost/ajax-loader.gif' alt='loader' style='padding-left:15px;'/&gt;");
  
      $("body").prepend(div);
      $("#dialog").dialog();
  
  
      var script = $.ajax({url: "http://localhost/parse.php", data: documentInfo, async: false}).responseText;
      $("#dialog").html(script);
  
  
  });
  </code></pre>