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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:52:16+00:00 2026-05-16T16:52:16+00:00

I’m trying to create a dynamic portfolio gallery where you can hide show items

  • 0

I’m trying to create a dynamic portfolio gallery where you can hide show items by clicking categories. Everything works apart from adding a class to elements hidden/showing when categories are clicked.

I currently have:

$(document).ready(function() {
 $('ul.filter a').click(function() {
  $(this).css('outline','none');
  $('ul.filter .current').removeClass('current');
  $(this).parent().addClass('current');
  
  var filterVal = $(this).text().toLowerCase().replace(' ','-');
    
  if(filterVal == 'all') {
   $('div.portfolio .hidden').fadeIn('slow').removeClass('hidden');
  } else {
   
   $('div.portfolio').each(function() {
    if(!$(this).hasClass(filterVal)) {
     $(this).fadeOut('normal').addClass('hidden');
    } else {
     $(this).fadeIn('slow').removeClass('hidden').addClass("show");
     
     $('.portfolio:visible').each(function (i) {
      if (i % 2 == 0) $(this).addClass("last"); // This is the part that doesn't seem to work
     });
         
    }
   });
  }
  
  return false;
 });
});

It’s this part of the code that seems to have the problem:

$('.portfolio:visible').each(function (i) {
    if (i % 2 == 0) $(this).addClass("last");  // This is the part that doesn't seem to work
});

Basically, I’m looking to add the class .last to every second "visible" item in my portfolio list.

Anyone?


CSS

/* --------------  Portfolio List  ---------------- */
#portfolio-items {
    font-size: 11px;    
}

#portfolio-items ul, #portfolio-items li {
    list-style:none;    
}
#portfolio-items .portfolio {
    float:left;
    width:265px;
    height:145px;
    margin:0px 60px 50px 0px;
    display:block;
}
#portfolio-items .portfolio .portfolio-client {
    float:left;
    font-size: 11px;
    color: #666;
    text-decoration: none;
}
#portfolio-items .portfolio.last {
    margin-right:0px;   
}
#portfolio-items .portfolio img {
    border:solid 6px #fff;
    -moz-box-shadow: 1px 1px 3px #999; /* Firefox */
    -webkit-box-shadow: 1px 1px 3px #999; /* Safari, Chrome */
    box-shadow: 1px 1px 3px #999; /* CSS3 */
    margin: 0px 0px 5px;
    
    transition: all .3s; /* in Safari, every animatable property triggers an animation in .2s */
    -o-transition: all .3s; /* in Safari, every animatable property triggers an animation in .2s */
    -webkit-transition: all .3s; /* in Safari, every animatable property triggers an animation in .2s */
    -moz-transition: all .3s; /* in Safari, every animatable property triggers an animation in .2s */
    
    transform-origin: centre; /* in Safari, the origin for transformation */
    -o-transform-origin: centre; /* in Firefox, the origin for transformation */
    -webkit-transform-origin: centre; /* in Safari, the origin for transformation */
    -moz-transform-origin: centre; /* in Firefox, the origin for transformation */
}

#portfolio-items .portfolio img:hover {
    -moz-box-shadow: 1px 1px 6px #999; /* Firefox */
    -webkit-box-shadow: 1px 1px 6px #999; /* Safari, Chrome */
    box-shadow: 1px 1px 6px #999; /* CSS3 */
    
    transform: scale(1.05);
    -o-transform: scale(1.05);
    -webkit-transform: scale(1.05);
    -moz-transform: scale(1.05);
    
    box-shadow: 0px 0px 20px #ccc;
    -o-box-shadow: 0px 0px 20px #ccc;
    -webkit-box-shadow: 0px 0px 20px #ccc;
    -moz-box-shadow: 0px 0px 20px #ccc;
}

.view-project {
    background: url(/themes/cogo/default_site/images/view-project.png) no-repeat right center;
    display: block;
    float: right;
    height: 14px;
    width: 87px;
    padding-right: 20px;
    text-align: right;
}

HTML

<div id="portfolio-items"> 
    <div class="portfolio first cms content-management e-commerce clothing kids shops toys"> 
        <a href="http://ee.dev/portfolio/detail/be-my-bear"> 
            <img src="/images/sized/themes/site_themes/cogo/images/uploads/bemybear-project-254x139.jpg" width="254" height="139" title="Be My Bear" /> 
        </a>
        <a href="http://ee.dev/clients/be-my-bear" class="portfolio-client">Be My Bear</a> 
        <a href="http://ee.dev/portfolio/detail/be-my-bear" class="view-project"><span>View Project</span></a></div> 
    
    <div class="portfolio last cms content-management business-services"> 
        <a href="http://ee.dev/portfolio/detail/joloda"> 
            <img src="/images/sized/themes/site_themes/cogo/images/uploads/joloda1-254x139.jpg" width="254" height="139" title="Joloda International Ltd" /> 
        </a> 
        <a href="http://ee.dev/clients/joloda-international" class="portfolio-client">Joloda International</a> 
        <a href="http://ee.dev/portfolio/detail/joloda" class="view-project"><span>View Project</span></a></div> 
    
    <div class="portfolio first buddypress cms content-management wordpress business-services coaching events training"> 
        <a href="http://ee.dev/portfolio/detail/nwwn"> 
            <img src="/images/sized/themes/site_themes/cogo/images/uploads/nwwn-project-254x139.jpg" width="254" height="139" title="NWWN" /> 
        </a> 
        <a href="http://ee.dev/clients/north-wales-womens-network" class="portfolio-client">North Wales Women&#8217;s Network</a> 
        <a href="http://ee.dev/portfolio/detail/nwwn" class="view-project"><span>View Project</span></a></div> 
    
    <div class="portfolio last e-commerce jewellery shops"> 
        <a href="http://ee.dev/portfolio/detail/italian-world"> 
            <img src="/images/sized/themes/site_themes/cogo/images/uploads/italianworld-254x139.jpg" width="254" height="139" title="Italian World" /> 
        </a> 
        <a href="http://ee.dev/clients/italian-world" class="portfolio-client">Italian World</a> 
        <a href="http://ee.dev/portfolio/detail/italian-world" class="view-project"><span>View Project</span></a></div> 
    
    <div class="portfolio first cms content-management drupal designers printers"> 
        <a href="http://ee.dev/portfolio/detail/mms-almac"> 
            <img src="/images/sized/themes/site_themes/cogo/images/uploads/mms-project-254x139.jpg" width="254" height="139" title="MMS Almac" /> 
        </a> 
        <a href="http://ee.dev/clients/mms-almac-ltd" class="portfolio-client">MMS Almac Ltd</a> 
        <a href="http://ee.dev/portfolio/detail/mms-almac" class="view-project"><span>View Project</span></a></div> 
    
    <div class="portfolio last cms content-management charity community training"> 
        <a href="http://ee.dev/portfolio/detail/europe-direct"> 
            <img src="/images/sized/themes/site_themes/cogo/images/uploads/europedirect-project-254x139.jpg" width="254" height="139" title="Europe Direct" /> 
        </a> 
        <a href="http://ee.dev/clients/ectarc" class="portfolio-client">Ectarc</a> 
        <a href="http://ee.dev/portfolio/detail/europe-direct" class="view-project"><span>View Project</span></a></div>     
</div>?

FILTER MENU

<ul class="filter">
  <li class="booking-systems"><a href="http://ee.dev/portfolio/category/booking-systems">Booking Systems</a></li> 
  <li class="buddypress"><a href="http://ee.dev/portfolio/category/buddypress">Buddypress</a></li> 
  <li class="cms"><a href="http://ee.dev/portfolio/category/cms">CMS</a></li> 
  <li class="content-management"><a href="http://ee.dev/portfolio/category/content-management">Content Management</a></li> 
  <li class="drupal"><a href="http://ee.dev/portfolio/category/drupal">Drupal</a></li> 
  <li class="e-commerce"><a href="http://ee.dev/portfolio/category/e-commerce">E-Commerce</a></li> 
  <li class="silverstripe"><a href="http://ee.dev/portfolio/category/silverstripe">Silverstripe</a></li> 
  <li class="wordpress"><a href="http://ee.dev/portfolio/category/wordpress">Wordpress</a></li> 
</ul>
  • 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-16T16:52:17+00:00Added an answer on May 16, 2026 at 4:52 pm

    You’ll need to use the :odd selector:

    http://api.jquery.com/odd-selector/

    Not exactly sure how to implement it in your code, but probably something like $('.portfolio:odd') or even $('.portfolio:visible:odd').

    I’ll give it a try in jsfiddle in a second.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.