title: javascript or jquery equivalent of PHP's strtok()?
body: <p>Is there a javascript equivalent to PHPs strtok()? In PHP, I'd use </p>
  
  <pre><code>$sub = strtok($string, ':'); 
  </code></pre>
  
  <p>(<a href="https://stackoverflow.com/questions/7829822/extract-text-from-string-up-to-colon-if-exists">Thanks to Phil's answer for that</a>)</p>
  
  <p>However, I need to do the same in javascript.</p>
  
  <p>I have a select list that contains values like this:</p>
  
  <pre><code>&lt;select id="myFonts"&gt;
      &lt;option value='Leckerli One'&gt;Leckerli One&lt;/option&gt;
      &lt;option value='Lekton:regular,italic,bold'&gt;Lekton (plus italic and bold)&lt;/option&gt;
      &lt;option value='OFL Sorts Mill Goudy TT:regular,italic'&gt;OFL Sorts Mill Goudy TT (plus italic)&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>And in the jQuery change event, I need to extract the "value" field. However, if the value field contains a colon, I need to pull the string contents before the colon and return nothing after it.</p>
  
  <p>For instance, in my example above, I need the values returned:</p>
  
  <p>Leckerli One
  Lekton
  OFL Sorts Mill Goudy TT</p>
  
  <p>Here's my jQuery currently (does not work properly when value contains the colon and additional properties):</p>
  
  <pre><code>$('#myFonts').change
  (
      function()
      {
      var myFont = $('#myFonts :selected').val();
      $('#fontPreviewSrc').attr('href','http://fonts.googleapis.com/css?family='+myFont);
      $('.fontPreview').attr('style','font-family:'+myFont+';font-style:normal;font-size:2em;padding-top:10px;white-space:nowrap');
      }
  );
  </code></pre>