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

后端 未结 2 1961
梦如初夏
梦如初夏 2021-02-06 17:00
2条回答
  •  北海茫月
    2021-02-06 17:58

    One approach, assuming the text you're searching for is exactly the string you use, shamelessly stealing from paying 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:

    • Jonathan Sampson:
      • The blog entry for :exactly() selector: http://sampsonblog.com/279/creating-your-own-custom-jquery-filters
      • The Stack Overflow question that prompted the creation of :exactly(): Is there any selector to do a perfect match against text?

提交回复
热议问题