如果子级具有“PageText_L657n”类,则尝试将类添加到具有“pricecolor”类的字体标记。
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="64%" valign="top"> Stock Item (Usually Ships Within 24 Hours) <br>
<font class="text colors_text"><span class="PageText_L483n"><b><span class="PageText_L334n">MSRP</span>: $4,895.00</b> </span></font><br>
<b><font class="pricecolor colors_productprice"><span class="PageText_L483n"><font class="text colors_text"><b>Regular Price: </b></font> $1,872.34 </span></font></b><br>
<br>
<a class="pricecolor colors_productprice"><span class="PageText_L657n"><span style="font-size: 16px; color: rgb(0, 0, 255);">Click To Get Today's Special Price!</span></a></td>
<td width="36%" align="right"></td>
</tr>
</tbody>
</table>
<script>
$(function(){
$(".pricecolor").child().hasClass("PageText_L657n").addClass("ice1");
});
</script>
最佳答案
使用:has()
选择器:
$('.pricecolor:has(.PageText_L657n)').addClass('ice1');
关于如果子类有类 xxx,jquery 添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5007510/