You're definitely heading in the right direction. It looks like you're trying to target td
elements within each tr
that contain a space.
One approach you could take is to use the filter
method on the td
elements, selecting only those that have a space present. You can then adjust the styling of those selected td
elements using CSS properties as needed.
Important Note: Whether there's one space, multiple spaces, or no content at all within the td
element, it won't be affected by this filter. However, if the content includes
, it will continue to remain visible based on your requirements mentioned in the question title.
$('.wrap_class_adv tr').each(function () { // Loop through each tr
$(this).find("td").filter(function() { // Filter td elements
return (this.innerText == ""); // Check for empty innerText
}).css('visibility', 'hidden'); // Toggle visibility with css
});
td { border: 1px solid #000; padding: 4px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="wrap_class_adv">
<tr>
<td>321</td>
<td>123</td>
<td> </td> <!-- Contains one space -->
<td> </td> <!-- Contains three spaces -->
<td> </td> <!-- remains visible -->
</tr>
</table>