html - Jquery changing table cell colour -
i have been trying working on own, , have given up. got bulk of code off , other sites googled.
what trying alter background-color
of first <td>
based on value of lastly <td>
this have @ moment, cant seem other colour working other first if statement
:(
$(document).ready(function() { $("#tabledata tr:not(:first)").each(function() { //get value of table cell var colour = $(this).find("td:nth-child(4)").html(); alert(colour); //check colour if (colour = "red") { //change color of background $(this).find("td:nth-child(1)").css("background-color", "red"); } else if (colour = "green") { $(this).find("th:nth-child(1)").css("background-color", "green"); } else if (colour = "blue") { $(this).find("th:nth-child(1)").css("background-color", "blue"); } }); });
i have created fiddle see experiencing. please allow me know how have alter dynamically based on cell value?
thanks! mike
is trying do? don't need if statement. pass colour
value background-color
such
$(this).find("td:nth-child(1)").css("background-color", colour);
fiddle: http://jsfiddle.net/5gcvoqfn/2/
jquery html css colors html-table
No comments:
Post a Comment