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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:31:45+00:00 2026-05-28T00:31:45+00:00

http://jsfiddle.net/nicktheandroid/QhL2M/ (type bye into the input box) Purpose of the script: Each li contains

  • 0

http://jsfiddle.net/nicktheandroid/QhL2M/
(type “bye” into the input box”)

Purpose of the script: Each li contains tag words in it. When the user types one of these tag words in the input box, it will hide all of the li‘s that do not contain that tag word. Multiple words may be typed into the input, if more than 1 li‘s tag words matches any of the words in the input, then they are shown. So it’s basically a filtered list that allows for multiple words, and shows all matching li‘s that contain any of the words typed into the input. It only matches whole words, not partial words, and it should only update the list of matches when another whole word has been matched(when multiple words). This is the goal.

My problem is that it’s incorrectly reporting that there’s a match in this piece of code:

 if (matches == true) {
    alert('matched true')  //incorrectly reports  
 } else {
    alert('matched false') //incorrectly reports  
 }

while this piece of code is reporting correctly:

if (regex.test($(this).text()) === true) {
    matches = true;
    // alert('tis true') //correctly reports  
} else {
       matches = false;
       // alert('tis false') //correctly reports   
}

Why is it not reporting correctly? (correctly, as in: what I want it to report)

If anyone is good enough at Javascript to see what i’m trying to do and knows how to help me, that’d be fantastic. I’m trying to work my way through this because there’s just a few things left to change.

  • 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-05-28T00:31:46+00:00Added an answer on May 28, 2026 at 12:31 am

    I think the problem is that you are looping through all of the list items with:

    $("#list li").each(function() {
    

    and then within each iteration you loop through the list of words with:

    $.each(inputWords, function(i, a_filter) {
    

    and then in the inner loop you again process all li elements with:

    var containing = $('#list li').filter(function () {
    

    So then in the inner part you’re getting confused about just what you’re dealing with. I think what you need to do is loop through each element, testing if it has any matches to the input word list, and then hide or show that element as appropriate. Something like this:

    var inputWords = inputValue.toLowerCase().split(/[\s,]+/);
    
    $("#list li").each(function() {
        var matches = false,
            $currentElement = $(this);
    
        $.each(inputWords, function(i, a_filter) {
            if ($.trim(a_filter)==="") return; // skip blank items
    
            var regex = new RegExp('\\b(' + a_filter + ')(s|es|\'s)?\\b', 'i');
            if (regex.test($currentElement.text())) {
                matches = true;
                return false;  // return false breaks out of the $.each
                               // (no need to continue once a match is found)
            }
         });
    
         if (matches)
            $currentElement.slideDown(400);
         else
            $currentElement.slideUp();
    });
    

    Working demo: http://jsfiddle.net/QhL2M/19/

    EDIT: also the way you were splitting the input word list didn’t work for me:

    var inputWords = $('.filterinput').text().toLowerCase().split(/[\s,]+/);
    // I've changed that to
    var inputWords = inputValue.toLowerCase().split(/[\s,]+/);
    

    You don’t want to use .text() on an input, and in any case inputValue was already initialised earlier to hold the text of that input. My code above and demo have been updated.

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

Sidebar

Related Questions

http://jsfiddle.net/nicktheandroid/yshcR/2/ you can type into the input box any of the words you see
http://jsfiddle.net/nicktheandroid/7raYa/9/ My script allows me to scroll the page like a PDF, allowing you
http://jsfiddle.net/nicktheandroid/6BAfH/1/ The list-elements are sorted accordingly by the number in their span. Why is
http://jsfiddle.net/aam7J/ How would I induce div-like behaviour on the input element? Specifically, how can
http://jsfiddle.net/nicktheandroid/SsfpG/ I don't understand why these inline elements are causing the paragraph to stop
http://jsfiddle.net/motocomdigital/c8Mey/1/ I'm using a twitter script which i'm binding a function to get the
http://jsfiddle.net/jasondavis/Mt87G/1/ I am trying to do an un-ordered list, each list item will have
http://jsfiddle.net/danielcgold/SYgzJ/ When you click on the input then go on blur, artifacts are left
http://jsfiddle.net/nicktheandroid/B7Rhe/5/ I'm trying to make the next slide fade in over the current slide,
http://jsfiddle.net/nicktheandroid/TWKJb/5/ Once you grab the handler and start to drag it, the handlers left

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.