Hide all 'a' elements with text or innerHTML that matches the number '0' or a custom value using javascript or jQuery

家住魔仙堡 提交于 2019-12-03 00:47:41
$('a:contains(foo)').hide();

Done.

Or:

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

With the later option you custom it a lot more, like:

var customValue = "foo"
$('a').filter(function(){
    return this.innerHTML === customValue &&
           $(this).closest('div').length;
}).fadeOut();
David Thomas

One approach, assuming the text you're searching for is exactly the string you use, shamelessly stealing frompaying homage to Jonathan Sampson:

Creating the :exactly selector:

$.extend($.expr[":"], {
    exactly: function( element, index, details, collection ){
        return $(element).text() === details[3];
    }
});

Used like so:

$('a:exactly("foo")').fadeOut();

References:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!