1

如果孩子的类别为“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>
4

3 回答 3

4

使用:has()选择器:

$('.pricecolor:has(.PageText_L657n)').addClass('ice1');
于 2011-02-15T18:03:07.747 回答
3

编辑:澄清后,似乎你想要这个:

示例:http: //jsfiddle.net/WeCCT/2/

$('.PageText_L657n').closest('td').find('.pricecolor').eq(0).addClass('ice1');

这将选择具有 class 的元素PageText_L657n,然后获取其最近的祖先<td>并使用find()(docs)方法定位嵌套.pricecolor元素,并在添加类之前使用eq()(docs)方法将其缩小到第一个。


原始答案

如果您想限制自己使用有效的querySelectorAll选择器,请执行以下操作:

$('.PageText_L657n').parent('.pricecolor').addClass('ice1');

This starts with selecting the .PageText_L657n element, then traverses up to its parent and only adds the class if the parent has the .pricecolor class.

于 2011-02-15T18:05:35.667 回答
0

The .pageText classes are only in the markup when you are an administrator for that site. Your store will not render your css code on the frontend when you are not logged in because those classes do not exist in the source anymore. I had the same problem since I was always coding while I was logged in to the site.

于 2013-05-23T05:14:22.240 回答