Is there a case insensitive jQuery :contains selector?

后端 未结 12 2395
悲哀的现实
悲哀的现实 2020-11-22 02:45

Is there a case insensitive version of the :contains jQuery selector or should I do the work manually by looping over all elements and comparing their .text() to my string?<

12条回答
  •  半阙折子戏
    2020-11-22 02:52

    May be late.... but,

    I'd prefer to go this way..

    $.extend($.expr[":"], {
    "MyCaseInsensitiveContains": function(elem, i, match, array) {
    return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
    }
    });
    

    This way, you DO NOT tamper with jQuery's NATIVE '.contains'... You may need the default one later...if tampered with, you might find yourself back to stackOverFlow...

提交回复
热议问题