Afternoon,
I would like to know how i can add a class depending on the returned value from a web service.
$.each(result, function (index, res) {
new_record = "<tr>" +
"<th scope=\"row\" class=\"t-left\"><a href=\"editproduct.aspx?sku=" + res.sku + "\" title=\"Edit this product listing\">" + res.title + "</a></th>" +
"<td><a href=\"http://www.amazon.co.uk/dp/" + res.asin + "\" target=\"_blank\" title=\"Visit the Amazon product listing\" >" + res.asin + "</a></td>" +
"<td>" + res.sku + "</td>" +
"<td>" + res.stock + "</td>" +
"<td> £" + res.price + "</td>" +
"<td>" + res.live + "</td>" +
"</tr>";
$('#dataResults').append(new_record);
I am also returning a value stockUpdated, and i would like to add a class to change the color of the stock table field depending if this comes back true.
I cant remember how i have done this previously but its similar to an if statement
Many thanks in advance.
Alan
Assuming I’ve understood your question correctly, you can just append the class attribute to the string depending on whether or not your
stockUpdatedproperty evaluates to true or not:I’ve done it inline with a tertiary conditional just because I like to keep the string concats all together. You could just as easily stop the concatenation at the end of the previous
tdand then wrap a fullifstatement around the nexttd.