如何在jquery上选择文本节点而不选择sibling
我有一些HTML的结构如下:如何在jquery上选择文本节点而不选择sibling,jquery,Jquery,我有一些HTML的结构如下: <div class="ProductPriceRating"> <em> <strike class="RetailPriceValue">$65.00</strike> $45.00 </em> </div> 但是它没有如果无法将样式应用于文本节点,则需要使用元素将其包装起来 试一试 var节点=$('.ProductPriceRating
<div class="ProductPriceRating">
<em>
<strike class="RetailPriceValue">$65.00</strike>
$45.00
</em>
</div>
但是它没有如果无法将样式应用于文本节点,则需要使用元素将其包装起来 试一试
var节点=$('.ProductPriceRating strike').get(0).nextSibling;
$(node).wrap(“”).parent().css('background','red');
演示:您不能直接设置文本节点的样式,而是将其包装在一个跨度中,并设置以下样式: HTML
<div class="ProductPriceRating">
<em>
<strike class="RetailPriceValue">$65.00</strike>
<span>$45.00</span>
</em>
</div>
如果无法更改HTML结构,可以尝试设置em
和strike
的样式:
$('.ProductPriceRating em').css('background','red');
$('.ProductPriceRating strike').css('background','white');
我的目标是45美元,而不是65美元
<div class="ProductPriceRating">
<em>
<strike class="RetailPriceValue">$65.00</strike>
<span>$45.00</span>
</em>
</div>
$('.ProductPriceRating strike').siblings().css('background','red');
$('.ProductPriceRating em').css('background','red');
$('.ProductPriceRating strike').css('background','white');