我正在关注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>
我不想显示整个
<td id="td0" style="width:180px;" class="even">
td的class和id将动态更新。
如果td
中不存在<span class="manufacturer_links">
怎么做?
答案 0 :(得分:2)
使用选择器魔术:
$('td:not(:has(span.manufacturer_links))').addClass('collapsed');
答案 1 :(得分:1)
jQuery的:
$("td#td0").not(":has(span.manufacturer_links)").css("display", "none");
答案 2 :(得分:1)
您可以检查它是否存在,然后执行任何操作:
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();
}