title: Programmatically add an element to modal dialog
body: <p>I'm trying to add a div element programmatically to a modal-dialog in SP2010.</p>
  
  <p><strong>Here's what I've already tried</strong>:</p>
  
  <p>This function to fire from the Master Page:</p>
  
  <pre><code>        function addDialogBanner(){
              var dbody = $(".ms-dialog").find("div[id$='MSO_ContentDiv']");
  
              var diaBanner = document.createElement('div');
              diaBanner.id = 'diaBanner';
  
              $(dbody).prependChild(diaBanner);
  
              $("#diaBanner").text("WOW. SUCH BANNER.");
          }
  </code></pre>
  
  <p>Which is supposed to piggy-back off of this (which is added to the onload function array, also on the Master Page):</p>
  
  <pre><code>        function addNewItemFix() {
              $(".ms-addnew").each(function () {
                  if ($(this).is("a")) {
                      var gReference = $(this).attr("href");
                      var options = {
                          title: "New Item",
                          url: gReference
                      };
  
                      $(this).attr("onclick", "javascript:SP.UI.ModalDialog.showModalDialog({title: 'New Item',url:'" + gReference + "', dialogReturnValueCallback:RefreshOnDialogClose}); addDialogBanner(); return false;");
                  }
              });
  
          }
  </code></pre>
  
  <p>I've added that method in because custom functionality didn't open up modal dialogs for new items. The issue I'm running into is that it seems that my script is executing before the modal dialog even finishes loading, so none of my jQuery selectors don't even exist yet. I want to stay away from <code>setTimeout</code> because load times aren't always consistent. As well, I have hundreds of sites and thousands of libraries that make an individual fix impossible.</p>
  
  <p>Is the entire way I'm going about this wrong? Or am I missing some kind of key information to get this working?</p>
  
  <p>EDIT 2/14/14:</p>
  
  <p>I've found out using a separate method to call the <code>SP.UI.ModalDialog...</code> won't actually call the dialog. It will pull up the dialog, then redirect to the aspx page. Is there something I'm missing?</p>