title: jQuery: Check if an object has class
body: <p>Trying to check if an object has a class. Seems simple enough, but I can't get it to work. Here is my code:</p>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>$('ul.nav li').click(function(){    
      if $(this).hasClass('selected') {
          alert('This is selected!');
      }
  
      else {
          alert('This is not selected!');
      }
  });
  
  $('ul.nav li:first-child').addClass('selected');
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;ul class="nav"&gt;
      &lt;li&gt;Who we work for&lt;/li&gt;
      &lt;li&gt;Articles and interviews&lt;/li&gt;
      &lt;li&gt;Job openings&lt;/li&gt;
      &lt;li&gt;What the #%!$@ is Post Typography?&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;ul class="content"&gt;
      &lt;li&gt;This is who we work for.&lt;/li&gt;
      &lt;li&gt;These are articles and interviews.&lt;/li&gt;
      &lt;li&gt;These are our job openings.&lt;/li&gt;
      &lt;li&gt;This is some info about Post Typography.&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>