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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:03:22+00:00 2026-06-14T14:03:22+00:00

I set out on a journey to create an iTunes-like search using Javascript. I

  • 0

I set out on a journey to create an iTunes-like search using Javascript. I learned about jQuery, and with some help from people on StackOverflow, I was successful.

I’ve come back here to share with you a very simple way to create a dynamic hide/show list based on the user input.

Let's search!

The entirety of the tutorial code can be found here.

And a JSFiddle for it is here!

  • 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-14T14:03:23+00:00Added an answer on June 14, 2026 at 2:03 pm

    First, create a simple Div Layout with some text in the divs and search bar above it.

        <div class="search_bar">
          <form><!--The Field from which to gather data-->
            <input id="searchfield" type="text" onclick="value=''" value="Case Sensitive Search">
          </form>
        </div>
        <!--Containers With Text-->
        <div class="container">
          <div class="container_of_hc">
            <div class="horizontal_containers">Cat</div>
            <div class="color">Black</div>
            <div class="color">White</div>
            <div class="color">Orange</div>
          </div>
          <div class="horizontal_containers">Dog</div>
          <div class="horizontal_containers">Rat</div>
          <div class="horizontal_containers">Zebra</div>
          <div class="horizontal_containers">Wolf</div>
        </div>
    

    CSS:

          .container {
            width: 100%;
          }
          .horizontal_containers {
            height:10%;
            border: solid 3px #B30015;
            font-size: 45px;
            text-align: center;
          }
    

    Second, you will make a script utilizing jQuery. Remember the title says this is a Dynamic Search, meaning (for us) we want to update the search with each key typed:

    $("#searchfield").keyup(function() { 
    

    Note: Need a selector refresher?

    Then we will set a variable to the value in #searchfield:

      var str = $("#searchfield").val();  //get current value of id=searchfield
    

    To ensure we show all the divs in our list when there is nothing in the searchfield we create an if statement based on the length of our new variable (str):

      if (str.length == 0) {
        //if searchfield is empty, show all
        $(".horizontal_containers").show();
      }
    

    Last, we do the actual hiding of the divs if the length of str is not 0:

      else {
        //if input contains matching string, show div
        //if input does not contain matching string, hide div
        $("div:contains('" + str + "').horizontal_containers").show();
        $("div:not(:contains('" + str + "')).horizontal_containers").hide();
      }
    });
    

    The div:contains() and div:not(:contains()) statements are what set the conditions. It’s essentially an if statement. They search the text contained within the div, not the div attributes. If you want to search a deeper div structure you can use more than one selector in the script’s jQuery statements like so:

    if (str.length == 0) {
    //if searchfield is empty, show all
      $(".container .color").show();
      } else {
        //if input contains matching string, show div
        //if input does not contain matching string, hide div
        $(".container div:contains('" + str + "').color").show();
        $(".container div:not(:contains('" + str + "')).color").hide();
      }
    

    Replace the script statement you already have to give it a try.

    Note: The nesting structure of your divs must match that in your selector.

    And that’s essentially it. If you have tips to improve this, know how to change it to a case insensitive search, or anything else you can think of, please let me know!

    Thanks to MrXenoType I have learned case insensitivity for the :contains function.

    To create a case insensitive search for this project simply add:

    $.expr[":"].contains = $.expr.createPseudo(function(arg) {
        return function( elem ) {
            return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
        };
    });
    

    This creates a pseudo for the contains function. Place this code above your other script (within the same script) to make true for only this script.

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

Sidebar

Related Questions

Using this answer as a guide, I set out to create a select_year that
I have a model set out like so: class Rating # user_id, author_id end
Basically I have 2 classes, Manifest and BrowserAction, set out like this: public class
As a learning project, I'd like to set-out to make an ncurses-based UI for
I'm about to set out on developing a .NET class library that will be
I would like to know how to get the following result set out of
Currently, I have a CSV file set out like this: Element,Weight Hydrogen,1 Oxygen,16 Eventually
Firstly, let me set out what I'd like to do. Assume I have three
I may be going about this the wrong way, so I'll set out the
My array contains items set out like: item_name_1::item_description::item_value (so each item in the array

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.