title: Writing a string from a function to a div element using the text() method in jQuery
body: <p>Included below is the current code that I am using:</p>
  
  <pre><code>&lt;script type="text/javascript" &gt;
    function rightTopSidebarAd() {
      document.write ("Text to test!");  
    }
  &lt;/script&gt;
  
  &lt;div style="border:3px solid #FF0000" id="rightTopSidebar"&gt;
  
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
     $j('#rightTopSidebar').text(rightTopSidebarAd());
  &lt;/script&gt;
  </code></pre>
  
  <p>Here I have a simple function <code>rightTopSidebarAd()</code> that I would like to return or print the string "Text to test!". I would like the function to result in the content being placed inside the <code>rightTopSidebar</code> element.</p>
  
  <p>Currently it prints "Text to test!" just after the div because that is where the <code>text()</code> method is placed.  If I place the jQuery code above, then it is printed at that position.</p>
  
  <p><em>Note: I can not place the jQuery code inside the <code>div</code> because this is just a demo.  In the original page all the <code>div</code> elements will be spread around the webpage and I will have the jQuery functions stored in an external JavaScript file.</em></p>
  
  <p>EDIT: Guys, my fault: I did show a simple function </p>
  
  <pre><code>  function rightTopSidebarAd() {
      document.write ("Text to test!");  
    }
  </code></pre>
  
  <p>To illustrate my problem, as you say a simple "return" will fix this problem, but the real function is not so simple, I'm trying to return a OpenX code, please advice me how to do it with this function:</p>
  
  <pre><code> function rightTopSidebarAd() {
      document.MAX_ct0 ='{clickurl}';
  
      var m3_u = (location.protocol=='https:'?'https://one.mydomain.com/www/delivery/ajs.php':'http://one.mydomain.com/www/delivery/ajs.php');
      var m3_r = Math.floor(Math.random()*99999999999);
      if (!document.MAX_used) document.MAX_used = ',';
      document.write ("&lt;scr"+"ipt type='text/javascript' src='"+m3_u);
      document.write ("?zoneid=15&amp;amp;target=_blank");
      document.write ('&amp;amp;cb=' + m3_r);
      if (document.MAX_used != ',') document.write ("&amp;amp;exclude=" + document.MAX_used);
      document.write (document.charset ? '&amp;amp;charset='+document.charset : (document.characterSet ? '&amp;amp;charset='+document.characterSet : ''));
      document.write ("&amp;amp;loc=" + escape(window.location));
      if (document.referrer) document.write ("&amp;amp;referer=" + escape(document.referrer));
      if (document.context) document.write ("&amp;context=" + escape(document.context));
      if ((typeof(document.MAX_ct0) != 'undefined') &amp;&amp; (document.MAX_ct0.substring(0,4) == 'http')) {
          document.write ("&amp;amp;ct0=" + escape(document.MAX_ct0));
      }
      if (document.mmm_fo) document.write ("&amp;amp;mmm_fo=1");
      document.write ("'&gt;&lt;\/scr"+"ipt&gt;");
      document.write ("&lt;noscript&gt;&lt;a href='http://one.mydomain.com/www/delivery/ck.php?n=a8ed906c&amp;amp;cb={random}' target='_blank'&gt;&lt;img src='http://one.mydomain.com/www/delivery/avw.php?zoneid=15&amp;amp;cb={random}&amp;amp;n=a8ed906c&amp;amp;ct0={clickurl}' border='0' alt='' /&gt;&lt;/a&gt;&lt;/noscript&gt;");
   }  
  </code></pre>