title: Apply javascript for mobile or desktop only
body: <p>I have 2 scripts one that I would like to use for any screen width less than 990px and another for anything greater.  These scripts come from a 3rd party and only work on the actual domain (so testing will be hard for anyone else).</p>
  
  <p>Here are the scripts they gave me:</p>
  
  <p>For mobile: </p>
  
  <pre><code>&lt;script&gt;
      (function(){
          var t = document.getElementsByTagName("script")[0];
          var s = document.createElement("script"); s.async = true;
          s.src = "//integration.nfusionsolutions.biz/client/jh/widget/module/accordionchart/nfaccordion";
          t.parentNode.insertBefore(s, t);
      })();
      &lt;/script&gt;
  </code></pre>
  
  <p>For Desktop:</p>
  
  <pre><code>&lt;script&gt;
      (function(){
                  var t = document.getElementsByTagName("script")[0];
                  var s = document.createElement("script"); s.async = true;
                  s.src = "//integration.nfusionsolutions.biz/client/jh/widget/module/spottableextended/nfspotextended";
                  t.parentNode.insertBefore(s, t);
      })();
      &lt;/script&gt;
  </code></pre>
  
  <p>I have tried this for the desktop view but I know something is off.  </p>
  
  <p>For Desktop:</p>
  
  <pre><code> &lt;script&gt;
  
          (function(){
          var viewportWidth = $(window).width();
          if (viewportWidth &gt; 900) {
                      var t = document.getElementsByTagName("script")[0];
                      var s = document.createElement("script"); s.async = true;
                      s.src = "//integration.nfusionsolutions.biz/client/jh/widget/module/spottableextended/nfspotextended";
                      t.parentNode.insertBefore(s, t);
         } })();
          &lt;/script&gt;
  
  Any suggestions?
  
  UPDATE*** Code based on response below
  
      &lt;script&gt;
  if ( $(window).width() &gt; 990) {     
    (function(){
                  var t = document.getElementsByTagName("script")[0];
                  var s = document.createElement("script"); s.async = true;
                  s.src = "//integration.nfusionsolutions.biz/client/jackhunt/widget/module/spottableextended/nfspotextended";
                  t.parentNode.insertBefore(s, t);
      })();
  }
  else {
    (function(){
          var t = document.getElementsByTagName("script")[0];
          var s = document.createElement("script"); s.async = true;
          s.src = "//integration.nfusionsolutions.biz/client/jackhunt/widget/module/accordionchart/nfaccordion";
          t.parentNode.insertBefore(s, t);
      })();
  }
  &lt;/script&gt;
  </code></pre>