我找不到关于这个问题的具体帖子。
基本上,我想要实现的是隐藏Compare文本,如果data-product-id小于someValue
经过一番搜索,这就是我想出的。没有错误,但代码不会做任何事情。我确定我的代码是错误的。
有人可以向我解释我的代码有什么问题吗,如果你们包括/解释正确的方法会很有帮助。
$("a[data-product-id]").filter(function() {
return parseInt($(this).attr("data-product-id")) < 99335;
$('.show').addClass('hide');
});
.hide {
display: none !important
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" class="button" data-product-id="99336" rel="nofollow"><p class="show">Compare</p></a>
<a href="#" class="button" data-product-id="99335" rel="nofollow"><p class="show">Compare</p></a>
<a href="#" class="button" data-product-id="99334" rel="nofollow"><p class="show">Compare</p></a>
<a href="#" class="button" data-product-id="99333" rel="nofollow"><p class="show">Compare</p></a>