title: Stopping space-delimited function in jquery/javascript
body: <p>I have this bit of code (i didn't write it) which looks at <code>&lt;li&gt;</code> class names in a html document and then creates a checkbox based on it. e.g <code>&lt;li class="books"&gt;&lt;/li&gt;</code> - the checkbox would be labelled "books". However if you have a space in the class e.g <code>&lt;li class="book case"&gt;&lt;/li</code>> it creates two tags - book &amp; case. I don't want it to do this has i want to be able to have a checkbox made up of two words. In the code below it says "now i have a space-delimited string of all class names stored". I don't understand which bit is doing this though. Can anyone see anything obvious that could be changed so this doesn't happen?</p>
  
  <pre><code>var stringOfClassNames = '';
  
  // grab the class name of each list item to build that string
  $('.filterThis &gt; li').each( function (i) {
      var thisClassString = $(this).attr('class');
      stringOfClassNames = stringOfClassNames +' '+ thisClassString
  });
  
  // now i have a space-delimited string of all class names stored
  // in the stringOfClassNames variable.  
  // Trim spaces from the ends of that string:
  stringOfClassNames = jQuery.trim(stringOfClassNames);
  
  // i can't really do anything with it until it's an array, so
  // convert that string to an array.
  var arrayClasses = stringOfClassNames.split(' ');
  
  
  // now for the isolating the filter that is common to all.
  // must do before extracting only the unique classes
  // one way to approach: count the number of times classes occur, and
  // if any occur the same number of times as how many list items i have,
  // assume that class is common to all list items, and remove it from
  // the filter list. duplicate class on same item = problem, but 
  // i'm not thinking about that right now.
  // i've also chosen sort the pre-unique'd array
  // instead of sorting the unique'd array.  i think i have to for the count.
  var arrayClasses = arrayClasses;
  totalNumberOfItemsToFilter = $('.filterThis &gt; li').length;
  </code></pre>
  
  <p>there is more code if it is needed...</p>