Reputation: 7778
I am having following html
<td id="td0" style="width:180px;" class="even">
<strong>Bedroom</strong> <br>
<span class="manufacturer_links">
<a href="http://testsite.com/bedroom-furniture/beds.htm?manufacturer=2441">Coaster Furniture Beds</a>
</span>
<br>
<span class="manufacturer_links">
<a href="http://testsite.com/bedroom-furniture/bed-frames-headboards.htm?manufacturer=2441">Coaster Furniture Bed Frames & Headboards</a>
</span>
<br>
<br>
</td>
I do not want to display whole
<td id="td0" style="width:180px;" class="even">
class and id of td will be updating dynamically.
if <span class="manufacturer_links">
does not exist in the td
How to do that?
Upvotes: 0
Views: 2770
Reputation: 4865
You can check if it exists, then do anything you want:
if( $('#td0 .manufacturer_links').length == 0) { //the class we look for does not exist in td0 element
//do anything, such as delete the td?
$('#td0').remove();
}
Upvotes: 1
Reputation: 841
jQuery:
$("td#td0").not(":has(span.manufacturer_links)").css("display", "none");
Upvotes: 1
Reputation: 145388
Use selector magic:
$('td:not(:has(span.manufacturer_links))').addClass('collapsed');
Upvotes: 3