我希望在包含" NEW ARRIVALS的同一页面上有h1时删除#tagfilter元素。"
HTML:
<div class="inner">
<h1 class="pagetitle row">NEW ARRIVALS</h1>
<div class="close-row">
<div class="navdrop" id="tagfilter" name="tagfilter">
<a href="http://www.achengshop.com/collections/newarrivals">All</oa>
<a href="http://www.achengshop.com/collections/newarrivals/bras">Bras</oa>
<a href="http://www.achengshop.com/collections/newarrivals/crossbody">Crossbody</a>
<a href="http://www.achengshop.com/collections/newarrivals/jeans">Jeans</a>
<a href="http://www.achengshop.com/collections/newarrivals/pants">Pants</a>
<a href="http://www.achengshop.com/collections/newarrivals/pullovers">Pullovers</a>
<a href="http://www.achengshop.com/collections/newarrivals/satchels">Satchels</a>
<a href="http://www.achengshop.com/collections/newarrivals/shirts">Shirts</a>
<a href="http://www.achengshop.com/collections/newarrivals/tops">Tops</a>
<a href="http://www.achengshop.com/collections/newarrivals/totes">Totes</a>
<div>
</div>
</div>
JQUERY:
$(function () {
if ($("h1").contains("NEW ARRIVALS")) {
$("#tagfilter").remove();
}
});
答案 0 :(得分:1)
这样做:
$(function () {
if( $("h1:contains('NEW ARRIVALS')").length ) {
$("#tagfilter").remove();
}
});
或者:
$(function () {
$("h1:contains('NEW ARRIVALS')").length === 0 || $("#tagfilter").remove();
});
答案 1 :(得分:1)
尝试
$(":contains(NEW ARRIVALS)").is("h1") && $("#tagfilter").remove();
$(function () {
$(":contains(NEW ARRIVALS)").is("h1") && $("#tagfilter").remove();
console.log($("#tagfilter").is("*"))
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="inner">
<h1 class="pagetitle row">NEW ARRIVALS</h1>
<div class="close-row">
<div class="navdrop" id="tagfilter" name="tagfilter">
<a href="http://www.achengshop.com/collections/newarrivals">All</oa>
<a href="http://www.achengshop.com/collections/newarrivals/bras">Bras</oa>
<a href="http://www.achengshop.com/collections/newarrivals/crossbody">Crossbody</a>
<a href="http://www.achengshop.com/collections/newarrivals/jeans">Jeans</a>
<a href="http://www.achengshop.com/collections/newarrivals/pants">Pants</a>
<a href="http://www.achengshop.com/collections/newarrivals/pullovers">Pullovers</a>
<a href="http://www.achengshop.com/collections/newarrivals/satchels">Satchels</a>
<a href="http://www.achengshop.com/collections/newarrivals/shirts">Shirts</a>
<a href="http://www.achengshop.com/collections/newarrivals/tops">Tops</a>
<a href="http://www.achengshop.com/collections/newarrivals/totes">Totes</a>
<div>
</div>
</div>