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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:40:53+00:00 2026-05-10T20:40:53+00:00

I need a CSS selector that can find the 2nd div of 2 that

  • 0

I need a CSS selector that can find the 2nd div of 2 that has the same class. I’ve looked at nth-child() but it’s not what I want since I can’t see a way to further clarify what class I want. These 2 divs will be siblings in the document if that helps.

My HTML looks something like this:

<div class='foo'>...</div> <div class='bar'>...</div> <div class='baz'>...</div> <div class='bar'>...</div> 

And I want the 2nd div.bar (or the last div.bar would work too).

  • 1 1 Answer
  • 4 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. 2026-05-10T20:40:54+00:00Added an answer on May 10, 2026 at 8:40 pm

    UPDATE: This answer was originally written in 2008 when nth-of-type support was unreliable at best. Today I’d say you could safely use something like .bar:nth-of-type(2), unless you have to support IE8 and older.


    Original answer from 2008 follows (Note that I would not recommend this anymore!):

    If you can use Prototype JS you can use this code to set some style values, or add another classname:

    // set style: $$('div.theclassname')[1].setStyle({ backgroundColor: '#900', fontSize: '1.2em' }); // OR add class name: $$('div.theclassname')[1].addClassName('secondclass'); // pun intentded... 

    (I didn’t test this code, and it doesn’t check if there actually is a second div present, but something like this should work.)

    But if you’re generating the html serverside you might just as well add an extra class on the second item…

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

Sidebar

Related Questions

I need CSS selector that match all input tags where type is not checkbox
I'm struggling with a css selector. I need a css rule that returns all
I need to center a CSS menu that has an unknown width. I found
Possible Duplicate: jquery or css selector? select all id’s that start with I need
I need a div css boxes every time with html-php content, when its in
I need to read CSS settings for the div's width and height etc in
need to add a 2nd css stylesheet to a page. do i add a
We need a database driven CSS menu . How would you do that? I
I'm trying to get the css value of the background-image of some div, but
I'd like to attach images to specific words but cannot find the right CSS

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.