title: dynamic script element placement using js/jquery
body: <p>This question probably has an easy answer, yet it evades me. In the ads on my site (Adsense or otherwise), they provide a script tag (e.g. <code>&lt;script type='text/javascript' src='to/my/source'&gt;&lt;/script&gt;</code>) to place in the location I want the ad to appear.</p>
  
  <p>However, before I load the ad script, I want to test to see if the user is on a handheld device by testing the CSS <code>display</code> of a <code>div</code> in js. Like this:</p>
  
  <pre><code>if ($('#mydiv').css('display') == 'none') {
      //do not load the ad; do nothing
  } else {
      //load the ad script element at *this place*;
      //that is, where this conditional is placed
  }
  </code></pre>
  
  <p>My thought is to place this conditional in the same place as I would place the ad script normally. However, it's not working (just like I knew it wouldn't), and I can't figure out how to load the script tag in place. Thanks for the help.</p>
  
  <p>EDIT:<br>
  Here is my actual code:</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
  if ($('#sidebar-wrapper').css('display') == 'none') {
  
  } else {
      document.write("&lt;scr" + "ipt type='text/javascript' src='http://ads.blogherads.com/bh/32/320/310566/1343256/300a.js'&gt;" + "&lt;/scr" + "ipt&gt;");
  }
  &lt;/script&gt;
  </code></pre>