title: jquery, add/remove class when window width changes
body: <p>I've written out a very basic script to add/remove a class on load or when a window is resized.</p>
  
  <p>I was just wondering if there was a better way of doing this or if it is possible to reduce the lines of code.</p>
  
  <p>Basically I want to be able to alter the styles when the site is viewed on a smaller screen. I thought it would be best to add a new class to the html tag when it went under a certain width...</p>
  
  <p>Anyways here's my code.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   $(document).ready( function() {
      /* Check width on page load*/
      if ( $(window).width() &lt; 514) {
       $('html').addClass('mobile');
      }
      else {}
   });
  
   $(window).resize(function() {
      /*If browser resized, check width again */
      if ($(window).width() &lt; 514) {
       $('html').addClass('mobile');
      }
      else {$('html').removeClass('mobile');}
   });
  </code></pre>
  
  <p></p>
  
  <p>Thanks</p>
  
  <p>Gillian</p>