JSFiddle - React, Tailwind, and code Playground
by jfriend00
HTML
<table>
<tr>
<td colspan="1">
<p class="Hello_blue">Hello Stack Overflow1</p>
</td>
<td rowspan="1" colspan="2">
<p class="Hello_red">Hello Stack Overflow2</p>
<p class="Hello_red">defines red color,that class want to apply to</p>
</td>
<td rowspan="1" colspan="1">
<p class="Hello_orange">Hello Stack Overflow3</p>
</td>
</tr>
</table>
CSS
.blue {color: blue;}
.red {color: red;}
.orange {color: orange;}
JavaScript
// convert "Hello_blue" to "blue"
function convertClassName(src) {
return src.replace(/^.*?_/, "");
}
$("table p").each(function() {
$(this).closest("td").addClass(convertClassName(this.className));
});