当同一页面上有包含“NEW ARRVALS”的 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();
}
});
最佳答案
这样就可以了:
$(function () {
if( $("h1:contains('NEW ARRIVALS')").length ) {
$("#tagfilter").remove();
}
});
或者:
$(function () {
$("h1:contains('NEW ARRIVALS')").length === 0 || $("#tagfilter").remove();
});
关于javascript - 如果有特定文本则删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26520975/