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

The Archive Base Latest Questions

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

I have a problem displaying zebra list after filtering results. I have a zebra

  • 0

I have a problem displaying “zebra” list after filtering results.
I have a zebra list which display perfect here is the code:

$('ul li:odd').addClass('zebra_odd');
$('ul li:even').addClass('zebra_even');

The problem comes when I filter that list an input like this:

  $('input').keyup(function() {                   
    var textboxVal = $(this).val().toLowerCase();   
    $('ul li').each(function() {                    
    var listVal = $(this).text().toLowerCase();     
      if(listVal.indexOf(textboxVal) >= 0) {      
        $(this).show();                        
      } else {
        $(this).hide();                         
      }

i.e. on the list I have this values: a1, b1, a2, b2, a3, b3. The list display the values on zebra rows perfect, but if I filter the data i.e. “a” it will show me a1, a2, a3 all in white background, it kept the old odd, even values. Thanks

  • 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-06T00:23:57+00:00Added an answer on June 6, 2026 at 12:23 am

    You can write a function to Update odd,even classes after filtering the elements like this

    function setOddEven() {
        $('li:visible:odd').removeClass('odd even').addClass('odd');
        $('li:visible:even').removeClass('odd even').addClass('even');
    }
    $(function() {
        setOddEven();
        $('input').keyup(function() {
            var textboxVal = $(this).val().toLowerCase();
            $('ul li').each(function() {
                $this = $(this); // cache the object for better performance
                var listVal = $this.text().toLowerCase();
                if (listVal.indexOf(textboxVal) >= 0) {
                    $this.show();
                } else {
                    $this.hide();
                }
            });
            setOddEven();
        });
    });​
    

    Working Fiddle

    Dont forget the :visible selector, or it will take hidden elements into account and hence wont work properly.

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

Sidebar

Related Questions

I have a problem displaying my Ext.list component. Here is my code: Ext.define(iphone.view.customers.List, {
I have a problem with displaying images in WPF. Here's my code: <Button HorizontalAlignment=Left
i have a problem with displaying GoogleMap. Here is the website source code: http://pastebin.com/LjhVbEF7
I have a problem displaying the results of an sql query into a ListView
I have a problem displaying validation errors that are triggered by ui components which
I Have A problem In displaying JS Code In PHP My Code Is <?php
I have a problem with updating the value of property from code which is
i have a problem here of displaying a date type from ms access db
I have got a problem in displaying the nested list in IE, firefox displays
I have a problem displaying a View Controller when calling a segue from code

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.