如果子类有类 xxx,jquery 添加类

标签 jquery addclass

如果子级具有“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/

相关文章:

javascript - 适用于 Android 的 JQuery Mobile + PhoneGap - 加载 index.html 时出错

javascript - jQuery:无法获取图像的宽度和高度

javascript - 将 .active 类添加到 div

javascript - 使用 jquery 更改源后重新加载 video.js 播放器

Qt Webkit - 浏览器交互问题

jquery - 切换类和添加类之间的区别

jquery - 悬停不同元素时更改不同按钮的类

Jquery addClass() 使用垂直对齐 css 属性

javascript - jquery .html 之后无法寻址 Html 元素

jQuery .addClass 没有效果