remove content from duplicated td value
by miloud_eloumri
HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 4px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("button").click(function() {
var seen = [];
// loop on rows
$('.table tbody tr').each(function(rowIndex, rowElement) {
// for each row, loop on tds with value attribute
$(rowElement).find('td.check[value]').each(function(tdIndex, tdItem) {
const attrValue = $(tdItem).attr('value'); // check value attribute
if (!seen.includes(attrValue)) {
// if attribute value is not present in array, push it
seen.push(attrValue);
// and break the tds loop in this row
return false;
} else {
// else empty tds
$(tdItem).empty();
}
});
});
});
});
</script>
</head>
<body>
<table class='table'>
<thead>
<tr>
<th>New ID</th>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Build</th>
<th>Pay</th>
<th>Date</th>
<th>From</th>
<th>To</th>
<th>Max</th>
<th>Used ID</th>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Name</th>
<th>Phone</th>
<th>Cell</th>
<th>Email</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>year</td>
<td>make</td>
<td>model</td>
<td>build</td>
<td>pay</td>
<td>date</td>
<td>from</td>
<td>to</td>
<td>max</td>
<td class="check" value="1">1<br /><a href="#">View</a></td>
<td class="check" value="1">text1</td>
<td class="check"...