如果页面加载时存在另一个div,如何使用jquery从页面中删除元素
如果出现免费送货,我希望在页面加载时,统一费率div消失 当前HTML:如果页面加载时存在另一个div,如何使用jquery从页面中删除元素,jquery,Jquery,如果出现免费送货,我希望在页面加载时,统一费率div消失 当前HTML: <dl class="shipment-methods"> <dd>Free Shipping</dd> <dt style="margin-bottom: 5px;"> <input name="shipping_method" type="radio" class="validate-one-required-by-name
<dl class="shipment-methods">
<dd>Free Shipping</dd>
<dt style="margin-bottom: 5px;">
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="freeshipping_freeshipping" id="s_method_freeshipping_freeshipping">
<label for="s_method_freeshipping_freeshipping"><!--<b>Free Shipping:</b>--> Free <strong>
<span class="price">£0.00</span> </strong>
</label>
</dt>
<dd>Flat Rate</dd>
<dt style="margin-bottom: 5px;">
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="flatrate_flatrate" id="s_method_flatrate_flatrate">
<label for="s_method_flatrate_flatrate"><!--<b>Flat Rate:</b>--> Fixed <strong>
<span class="price">£9.95</span> </strong>
</label>
</dt>
</dl>
免费送货
免费
0.00英镑
统一费率
固定
9.95英镑
使用其长度检查是否存在freeshippingid
&隐藏其他项。您可以这样做:
if($('#s_method_freeshipping_freeshipping').length) {
$('#s_method_flatrate_flatrate').closest('dt').hide().prev().hide();
}
尝试将其添加到标题中,它似乎不起作用,但我可以看到它在JSFIDLE中起作用<代码>如果($('s#u方法_freeshipping_freeshipping').length){var parentDt=$('s#u方法_flatrate_flatrate').parent('dt');parentDt.hide();parentDt.prev('dd').hide()代码>@user2478101-不要在头上写脚本。使用脚本标记将其写入正文
。
if($('#s_method_freeshipping_freeshipping').length) {
$('#s_method_flatrate_flatrate').closest('dt').hide().prev().hide();
}