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
  • 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. 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

Often I find myself filling ASP.NET repeaters with items that need the CSS class
I'm trying to find a CSS selector that can help me distinguish between the
I need to style links for a Blackberry browser that has disabled CSS. The
Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Here is a snippet of CSS that I need explained: #section { width: 860px;
I have a set of nested DIV 's and I need to find each
i need to compress my css as part of my ant build. i noticed
I need to layout a html datatable with CSS. The actual content of the
I am building a menu in HTML/CSS/JS and I need a way to prevent
I don't edit CSS very often, and almost every time I need to go

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.