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 8126031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:00:56+00:00 2026-06-06T07:00:56+00:00

Story so far…. Hello Stackoverflowers, me again! Right, im learning JQuery at the moment

  • 0

Story so far….

Hello Stackoverflowers, me again! Right, im learning JQuery at the moment and i want to build a “search as you type” AJAX/JSON control. So off vie gone into JSFiddle to build a skeleton function and build on it, learning as i go. You have helped me in the past few days so thank you:

JQuery – Using Selector :contains – Weird Results

JQuery – Iterating JSON Response

Now im moving onto only showing the selected list items that match the input.

“so whats your problem now..” i here you groan! (and yes rlemon i have my eBook now!) 🙂

JQuery nOOb problem part 3: Multiple Selectors.

Ive been using the JQuery Multiple Selectors API guide so i understand how to include multiple selectors, but my issue is that mine isn’t selecting anything, i.e. :contains is not finding anything. Is this incorrect, ive used JSLint and it has parsed correctly with no errors:

$("li[id^='live'] li:contains('" + this.value + "')").show();

My full JSFiddle code is here but i have included it for ease as well:

http://jsfiddle.net/garfbradaz/JYdTU/88/

$(document).ready(function() {
var $input = $("#livesearchinput"),
    filled = false;
$.ajaxSetup({
    cache: false
});
$input.keyup(function(key) {
    if (!filled) {
        filled = true;
        $.getJSON("/gh/get/response.json//garfbradaz/MvcLiveSearch/tree/master/JSFiddleAjaxReponses/", function(JSONData) {
            var $ul =
            $('<ul>').attr({
                id: "live-list"
            }).appendTo('div#livesearchesults');
            $.each(JSONData, function(i, item) {
                $.each(item, function(j, val) {
                    $('<li>').attr({
                        id: "live-" + val
                    }).append(val).appendTo($ul).hide();
                });
            });
        });
    }

    var n = 0;

    if (this.value !== "") {
        n = $("li:contains('" + this.value + "')").length;
        n2 = $("li[id^='live'] li:contains('" + this.value + "')").length;
        console.log("1. value of n2 equals " + n2 + " : " + this.value + "end");


    }
    else {
        n = 0;
    }

    if (n <= 0) {
        $('li[id ^= "live"]').hide("slow");
        console.log("1. value of n equals " + n + " : " + this.value + "end");
    }

    if (n > 0) {
        $("li[id^='live'] li:contains('" + this.value + "')").show();
        console.log("2. value of n equals " + n + " : " + this.value + "end");
    }


});

});​

What ive done is put a console.log n2 is always 0, and here is the f12 log for proof:

proof

So my question are:

  1. How can i correct the multiple selector to include :contains so i know for future
  2. Should i even use :contains, or should i approach it differently and use .filter()? Before posting i was researching this issue and found a nice stack answer detailing the use of this:

JQuery Contains Selector – Multiple Text Items

  • 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-06T07:00:58+00:00Added an answer on June 6, 2026 at 7:00 am

    In your case you only need to combine two selectors: li id starts with and li contains. The similar part of each selector is li, so start with li and add the other two.

    $("li[id^='live']:contains('" + this.value + "')").length;
    

    http://jsfiddle.net/JYdTU/89/

    I only updated one line to make the console output correctly, you’ll have to go through the fiddle and update the rest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Story so far..... I want to learn JQuery, and im also building an MVC
I've got three entities in my application so far: tag, feed and story A
The story so far: I have a rails app with a model named Term.
OK, so here's the story so far. I could already deserialize individual objects using
Long story short, I'm using a buggy WordPress template and we're too far into
Ok, the story so far is i have a datatable, about 10,000 lines or
WARNING: Long and complicated question... So here's the story so far: I'm trying to
The Story So Far I've got a nice solution with a desktop application project,
Here's the story so far: I'm doing a C# winforms application to facilitate specifying
Here is the story so far: A client hired us to do an iPhone

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.