Is there a case insensitive jQuery :contains selector?

后端 未结 12 2334
悲哀的现实
悲哀的现实 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 03:05

    Refer below to use ":contains" to find text ignoring its case sensitivity from an HTML code,

     $.expr[":"].contains = $.expr.createPseudo(function(arg) {
                return function( elem ) {
                    return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
                };
            });
            $("#searchTextBox").keypress(function() {
              if($("#searchTextBox").val().length > 0){
                $(".rows").css("display","none");
                var userSerarchField = $("#searchTextBox").val();
                $(".rows:contains('"+ userSerarchField +"')").css("display","block");
              } else {
                $(".rows").css("display","block");
              }              
            });
    

    You can also use this link to find case ignoring code based on your jquery version, Make jQuery :contains Case-Insensitive

提交回复
热议问题