Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果页面加载时存在另一个div,如何使用jquery从页面中删除元素_Jquery - Fatal编程技术网

如果页面加载时存在另一个div,如何使用jquery从页面中删除元素

如果页面加载时存在另一个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

如果出现免费送货,我希望在页面加载时,统一费率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" 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英镑

使用其
长度检查是否存在freeshipping
id
&隐藏其他项。

您可以这样做:

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();
}