<li> 如果文本包含特定文本,则删除某些文本


有人能帮我吗
我知道这很简单,但我做不到。

我试图在我的网站上隐藏一些包含特定文本的行(shouldNotAppear(。到目前为止,我所做的工作在下面的代码中,但它不起作用。我能做的最好的事情就是用.remove((来做,但它扰乱了数组。

var shouldNotAppear = ['text1', 'text2', 'text3'];
for (var i in $(".brand li h4 .option-title")) {
if (shouldNotAppear.indexOf($(".brand li h4 .option-title")[i].innerText) != -1) {  
$(".brand h4")[i].hide();
};
var shouldNotAppear = ['text1', 'text2', 'text3'];
$('.brand li h4 .option-title')
// filter to only the titles that have a value that should not appear
.filter(function(){ return shouldNotAppear.includes(this.innerText); })
// for each title that should not appear, go up to their parent h4
.closest('h4')
// hide them
.hide();

最新更新