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

The Archive Base Latest Questions

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

I want .fourth added to the fourth .service-list when its inside: <section class=sixteen> When

  • 0

I want .fourth added to the fourth .service-list when its inside:

 <section class="sixteen">

When it’s any other class I want to add .third to the third .service-list.

e.g

 if ($("section").hasClass("sixteen")) {

     $('div.service-list').filter(function(index){
     return (index%4 == 3);
     }).addClass('fourth');

 } else {

     $('div.service-list').filter(function(index){
     return (index%3 == 2);
     }).addClass('third');
 }

However this seems to find ANY .sixteen on the page. I just want it to check the parent of the .service-list’s.

At the moment is finds another .sixteen down the page and adds .fourth when I need .third because it’s inside a smaller grid.

Here is a jsFiddle: http://jsfiddle.net/Xu3Yq/

  • 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-31T13:11:29+00:00Added an answer on May 31, 2026 at 1:11 pm

    How about this:

    $('section')​​​​​​​.each(function() {
        var $this = $(this);
    
        if ($this.hasClass('sixteen')) {
            $this.find('div.service-list:eq(3)').addClass('fourth');
        } else {
            $this.find('div.service-list:eq(2)').addClass('third');
        }
    });​
    

    http://jsfiddle.net/mzwqD/

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

Sidebar

Related Questions

I want to add two different class attributes to my my first and fourth
if i have an li list like this: <ul> <li>first </li> <li>second</li> <li>third</li> <li>fourth</li>
I want to have the second line (and third, fourth, etc.) of my TextView
I added the reachability.m and .h files. When theres no internet connection, i want
I want emacs to add last edit location to the mark ring, so I
I want to write an anonymous function taking a vector theta as its input
I want to create an action once, then add it to multiple sprites. For
I have a class that reads a pop3 email server. I want to write
I want to create list view just like this: http://dl.maximumpc.com/galleries/androidpower/Alarm_full.jpg I need to create
I want to create a game which goes back and fourth to the servlet

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.