Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:40:53+00:00 2026-06-18T05:40:53+00:00

I have a simple live search filter that runs as follow: jQuery.expr[‘:’].Contains = function(a,i,m)

  • 0

I have a simple live search filter that runs as follow:

jQuery.expr[':'].Contains = function(a,i,m) { 
    return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};

var $section = $('section');
var $noresults = $('#noresults');

$noresults.hide();

$('#search').bind('keyup focus', function() {
    var input = $(this).val();

    if(input) {
        $section.hide();
        var result = $("section:Contains('"+input+"')");

        if(result.length) {
            $noresults.hide();
            result.show();
        }
        else {
            $noresults.show();
        }
    }
    else {
        $noresults.hide();
        $section.show();
    }
});

It works fine but I was asked to make it accept multiple values. With this current filter, if I type “ABC” only the sections containing the string “ABC” will be displayed. Yet if I type “ABC DEF”, nothing will be displayed even though these two strings are contained in one or several sections of the document.

What I would like to obtain is a filter that only displays the sections containing the strings “ABC” and “DEF” when I type “ABC DEF” in the input field.

I tried a couple of solutions, that involve splitting the input, and came up with the following version but it does not work. Could you please help me make this filter accept multiple values?

$('#search').bind('keyup focus', function() {
    var input = $(this).val();

    var arr = input.split(/[ ,]+/);

    var len = arr.length;

    console.log(arr);
    console.log(len);

    for(var i=0; i<len; ++i) {  
        if(input) {
            $section.hide();

            var result = $("section:Contains('"+arr[i]+"')");

            if(result.length) {
                $noresults.hide();
                result.show();
            }
            else {
                $noresults.show();
            }
        }
        else {
            $noresults.hide();
            $section.show();
        }
    }
});

Thanks a lot for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:40:54+00:00Added an answer on June 18, 2026 at 5:40 am
    • Cache jQuery(a).text().toUpperCase()
    • Split query by whitespace
    • Loop over the split query, testing each one
    • If you find a query member that is not contained, return false
    • At loop end, return true

    Also note that if you don’t want to change your custom selector code, you can also write section:Contains('ABC'):Contains('DEF').

    EDIT: Translation:

    jQuery.expr[':'].Contains = function(a,i,m) { 
      var text = jQuery(a).text().toUpperCase();          // Cache `jQuery(a).text().toUpperCase()`
      var words = m[3].split(/\s+/);                      // Split query by whitespace
      for (var i = 0; i < words.length; i++) {            // Loop over the split query, testing each one
        if (-1 == text.indexOf(words[i].toUpperCase())) { // If you find a query member that is not contained,
          return false;                                   // return false
        }
      }
      return true;                                        // At loop end, return true
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple jquery function that utilize the .live function. It applies to
I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:
I have a simple jQuery function: $('#selectable1 span').live('mousedown', function() { var ff = $(this).css(font-family);
I have a simple jQuery function that resizes text areas, and I want it
I am designing a simple jquery live search function within a widget on a
I have simple JS loop jQuery('#checkbox-counter').live('click', function(){ jQuery.get('index.php?option=get_site_list=true', function(data){ console.log(data[1]); for(var index in data[1].id){
I have one simple gridview, I want to create a function in jquery that
I have a simple jquery ajax script that sends value to a web service
I have a simple url that will toggle one field in my search model.
How do I use jQuery to live search or filter items on a HTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.