title: How can I get only the first class of an element?
body: <p>I am trying to get the class of an element upon hovering on it.</p>
  
  <p>So far I have managed to get a bit of progress:</p>
  
  <pre><code>var classString = $(this).attr('class');
  </code></pre>
  
  <p>This gives me all the classes of the element (unfortunately more than one). For instance, if I do:</p>
  
  <pre><code>alert(classString);
  </code></pre>
  
  <p>I get the string "blog button main". I want to get just the first word of that string (the first class). I've tried:</p>
  
  <pre><code>var myClass = $(classString).text().split(' ')[0];
  alert(myClass);
  </code></pre>
  
  <p>expecting to get just "blog", but I get an empty string. I'm sure this is just a basic mistake I am making, but I can't see it.</p>