title: Assign to each user a color
body: <p>I am currently creating a web-chat and whenever a message is displayed in the chat-box, the user that sent the message is displayed and identified with a color. For every user I create a class and assign a value to the color style with the above function.</p>
  
  <pre><code>newHTML = '';
  
  $.each(data, function(index, element) {
  
      $('.user_' + element.senderId).attr("style","color:" + randColor());
  
      newHTML = newHTML + '&lt;div id="boxMsg"&gt;&lt;b&gt;&lt;span class="user_' + element.senderId + '"&gt;' 
                        + element.senderId + '&lt;/b&gt;&lt;/span&gt;&lt;/br&gt;' + element.message + '&amp;nbsp&amp;nbsp&lt;span class="dateMsg"&gt;' + dateTime.substring(11, 16) + '&lt;/span&gt;&lt;/div&gt;';    
  
      });
  
  $('#chatbox').append(newHTML);           
  },
  </code></pre>
  
  <p>A JSON protocol is used to extract all the information concerning the message displayed on the chat. But still it doesn't work and all the usernames are black. Do you know what am I doing wrong?</p>
  
  <p>Thanks in advance for your replies!</p>
  
  <p>EDIT: thanks to @Evan I solved the first part and the function to assign a random color works. But still, only the first and the third member of the chat color changes. The others are still black. Anyway, I leave the code for the function randColor().</p>
  
  <pre><code>function randColor(){
                  var letters = '0123456789ABCDEF'.split('');
                  var color = '#';
                  for (var i = 0; i &lt; 6; i++ ) {
                      color += letters[Math.floor(Math.random() * 16)];
                  }
                  return color;
              };  
  </code></pre>
  
  <p>EDIT.2: I have corrected the function to reflect more the one I am working on. </p>