I am trying to color code a td after checking certain condition from an array. Everything works fine except this piece. Here is what I have
<table border="0" cellpadding="0" cellspacing="0">
<th>First Name</th>
<th>Last Name</th>
<th>Profession</th>
<th>Code</th>
</table>
var html = "";
$.each(arrayTest, function () {
html += '<tr><td>' + this.firstName + '</td>';
html += '<td>' + this.lastName + '</td>';
html += '<td>' + this.profession + '</td>';
html += '<td class="colorType"></td><tr>';
if (this.type === 'red') {
$('.colorType').css('background', 'red')
}
else if (this.type === 'blue') {
$('.colorType').css('background', 'blue')
} else {
$('.colorType').css('background', 'white')
}
});
$('table').append(html);
Here is my fiddle http://jsfiddle.net/sghoush1/J2ssK/9/