JSFiddle - React, Tailwind, and code Playground
by pitaj
HTML
<table> <thead><th>id </th><th>name </th><th>number </th><th>result </th> </thead>
<tbody><tr><td>stuff</td><td>stuff</td><td>stuff</td><td>stuff</td> </tr></tbody>
</table>
JavaScript
(function($){
$.fn.colorColumn = function(headerText, color){
var index = this.find("th").filter(function(){
return ($(this).text() == headerText);
}).css("backgroundColor", color).index();
this.find("tr").each(function(){
$(this).children().eq(index).css({backgroundColor: color});
})
}
})(jQuery);
$("table").colorColumn("number", "red");