title: Split letters and assigning class
body: <p>I'm having problems with the following, I need to separate each character in a span and assign a class depending on the character with javascript.</p>
  
  <p>I have this:</p>
  
  <pre><code>&lt;div&gt;1111222&lt;/div&gt;     
  </code></pre>
  
  <p>and the final result should be this:</p>
  
  <pre><code>&lt;div&gt;
     &lt;span class="e1"&gt;1&lt;/class&gt;
     &lt;span class="e1"&gt;1&lt;/class&gt;
     &lt;span class="e1"&gt;1&lt;/class&gt;
     &lt;span class="e1"&gt;1&lt;/class&gt;
     &lt;span class="e2"&gt;2&lt;/class&gt;
     &lt;span class="e2"&gt;2&lt;/class&gt;
     &lt;span class="e2"&gt;2&lt;/class&gt;
  &lt;/div&gt;     
  </code></pre>
  
  <p>This is the code I'm using:</p>
  
  <pre><code>var str = $('.test').text();
  var result = "";
  str = str.split("");
  var h = $(this).text();
  $.each(str,function(){
  if( h = 1)
  {
      result += '&lt;span class="e1"&gt;' + this + '&lt;/span&gt;';
  }
  else if ( h = 2)
  {
      result += '&lt;span class="e2"&gt;' + this + '&lt;/span&gt;';
  }
  });
  $('.test').html($(result));    
  </code></pre>
  
  <p>Thanks</p>