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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:47:39+00:00 2026-05-31T23:47:39+00:00

I’ve been trying to get a sort of rudimentary filter working. Basically, you click

  • 0

I’ve been trying to get a sort of rudimentary filter working. Basically, you click on a link and it filters the list (see code below). This actually works fine. However, I’d like pretty it up a bit by fading out the current list (whether it’s filtered or not), and fading the list back in with the right filter applied.

Hope you get what I mean. Let me know if I don’t make any sense.

HTML:

filter by: <a href="#" class="clearfilter">all</a>
<h4>venue</h4>
<a href="#location1" class="filter">location1</a>, <a href="#location2" class="filter">location2</a>
<h4>photographer</h4>
<a href="#ben" class="filter">ben</a>, <a href="#ken" class="filter">ken</a>, <a href="#sam" class="filter">sam</a>, <a href="#susan" class="filter">susan</a>
<br/><br/>
<ul>
    <li class="ken location1"><a href="#">img 01</a></li>
    <li class="ken location1"><a href="#">img 02</a></li>
    <li class="ken location2"><a href="#">img 03</a></li>
    <li class="sam location2"><a href="#">img 04</a></li>
    <li class="sam location2"><a href="#">img 05</a></li>
    <li class="ben location2"><a href="#">img 06</a></li>
    <li class="ben location2"><a href="#">img 07</a></li>
    <li class="ben location2"><a href="#">img 08</a></li>
    <li class="susan location1"><a href="#">img 09</a></li>
    <li class="susan location1"><a href="#">img 10</a></li>
    <li class="susan location2"><a href="#">img 11</a></li>
    <li class="ken location2"><a href="#">img 12</a></li>
</ul>

​jQuery

$(document).ready(function() {
    $(".filter").click( function () {
        var filterText = $(this).attr('href').replace('#','');
        $("li").show().not('.'+filterText).hide();
    });

    $(".clearfilter").click( function() {
        $("li").show();
    });
});

CSS

li {
    margin-left:20px;
    margin-bottom:20px;
    border:1px solid red;
    width:40px;
    height:40px;
    display:block;
    float:left;
}
li a {
    width:40px;
    height:40px;
    display:block;
}​

​

I tried the usual fadeOut() and fadeIn() again but the filter seems to be applying to the already filtered list and nothing comes back. This si why I’ve got the initial show() in this line: $("li").show().not('.'+filterText).hide(); because that seems to reset the list.
But if I add the show() in it won’t fade properly.

Thanks in advance for your help. Fiddle link: http://jsfiddle.net/gxfBD/33/

EDIT:
It seems not even professionals get it right: http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-filterable-portfolio-with-jquery/. Theirs jumps about and shows items briefly that aren’t supposed to be shown, too. :/

EDIT AGAIN (ALTERNATIVE ANSWER):
Marc’s answer below gave me the kick-start I needed to work it out. my new jQuery is below:

var filterText = "all";

$(document).ready(function() {
    $(".filter").click( function () {
        filterText = $(this).attr('href').replace('#','');

        if(filterText == "all") {
            $("#gallery a").colorbox({rel:'gallery'});
        }
        else {
            $("#gallery ."+filterText+" a").colorbox({rel:filterText});
        }
        showFilterList(filterText);
    });

    $("#gallery a").colorbox({rel:'gallery'});
});

function showFilterList(value) {
    if (value == "all") {
        $("#gallery").animate({
            opacity: 0
        }, 500, function() {
            // Animation complete.
            $("#gallery li").show(); //remove the filter so everything shows
        }).animate({
            opacity: 1
        }, 500);
    }
    else {
        $("#gallery").animate({
            opacity: 0
        }, 500, function() {
            // Animation complete.
            $("#gallery li").show(); //remove the filter so everything shows
            $("#gallery li").not('.'+value).hide(); //apply the new filter
        }).animate({
            opacity: 1
        }, 500);
    }
}

I’ve also combined the colorbox plugin and added the call to my click event. This allows the “image x of y” text to be set with the new filtered number of images in the list.

Hope that helps someone else.

  • 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-31T23:47:40+00:00Added an answer on May 31, 2026 at 11:47 pm

    Try this: http://jsfiddle.net/gxfBD/74/

    I gave your <UL> an ID and changed the JS to this:

    $(document).ready(function() {
        $(".filter").click( function () {
            var filterText = $(this).attr('href').replace('#','');
            $("#ulid").hide(); //hide the whole div
            $("li").show(); //remove the filter so everything shows
            $("li").not('.'+filterText).hide(); //apply the new filter
            $("#ulid").fadeIn(1000); //fade in the div
        });
    });
    

    Note that if you want more control over the fadeOut() effect, you can do the filtering within a callback, like so:

    $(document).ready(function() {
        $(".filter").click( function () {
            var filterText = $(this).attr('href').replace('#','');
            $("#ulid").fadeOut(1000,
                               function(){
                                 $("li").show();
                                 $("li").not('.'+filterText).hide();
                               }
                          );
            $("#ulid").fadeIn(1000);
        });
    });
    

    If that isn’t what you’re looking for, then you’ll need to be more clear about what you are looking for.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.