使用javascript或jQuery隐藏所有带有text或innerHTML的'a'元素,这些元素匹配数字'0'或自定义值

Zea*_*apa 3 html javascript jquery innerhtml match

我需要使用javascript或jQuery 隐藏所有<a>带有文本或innerHTML匹配数字'foo'或自定义值的元素.

<li><a href="#" class="dir">foo</a></li>
Run Code Online (Sandbox Code Playgroud)

我试过了

jQuery(document).ready(function() {
    if (jquery().text().html("foo"){
        ('li >a').fadeOut()
    }
});
Run Code Online (Sandbox Code Playgroud)

gdo*_*ica 15

$('a:contains(foo)').hide();
Run Code Online (Sandbox Code Playgroud)

完成.

要么:

var customValue = "foo"
$('a').filter(function(){
    return this.innerHTML === customValue;
}).fadeOut();
Run Code Online (Sandbox Code Playgroud)

使用后面的选项,您可以更多地定制它,例如:

var customValue = "foo"
$('a').filter(function(){
    return this.innerHTML === customValue &&
           $(this).closest('div').length;
}).fadeOut();
Run Code Online (Sandbox Code Playgroud)