JSFiddle - React, Tailwind, and code Playground
by JonNorman
HTML
<table class="mytable" border="1">
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
</tr>
<tr class="data"><td>1st</td><td>1.1</td><td></td><td></td></tr>
</table>
<br/>
<table class="mytable" border="1">
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
</tr>
<tr class="data"><td>1st</td><td>1.1</td><td></td><td>1.3</td></tr>
</table>
JavaScript
$(document).ready(function() {
$('.mytable').each(function() {
$(this).find("th").each(function(i) {
var remove = true;
var tds = $(this).parents('table').find('tr td:nth-child(' + (i + 1) + ')');
if (tds.filter(":parent").length == 0) {
$(this).hide();
tds.hide();
}
});
});
});