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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:29:15+00:00 2026-06-12T22:29:15+00:00

I have some html where I want to add a class to all children

  • 0

I have some html where I want to add a class to all children except the first child.

    <div class="test">
        <div class="different">title</div>
        <div class="same">a</div>
        <div class="same">b</div>
        <div class="same">c</div>
    </div>

with the below js

<script>
$(".test").children().each(function(i) {
  $(this).addClass("eg_" + (i+1));
});
</script>

see this fiddle

http://jsfiddle.net/aaronk85/HaH2y/

I want every child div of test except the first one to get the class “eg_” + (i+1) and I can’t seem to get this working?

I have seen a few similar examples see the eg below but can’t quite work it out from this. Where have I gone wrong here?

http://jsfiddle.net/aaronk85/y9bEG/11/

  • 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-06-12T22:29:15+00:00Added an answer on June 12, 2026 at 10:29 pm

    Use gt to filter and a callback to set the precise class :

    $('.test > div:gt(0)').addClass(function(i){
          return 'eg_'+(i+2);
    });
    

    (it’s not clear in your question if you need i, i+1 or i+2)

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

Sidebar

Related Questions

I have a page with several .desc divs. I want to add some html
I have some html files and want to extract only lines with containing these
I have some html files that I want to convert to text. I have
I have some html files with their own css. I want to use them
I have some html extracted to a string var, and want to then use
I have some text that has HTML hyper-links in it. I want to remove
I have some data enclosed in HTML tags. I want to insert this data
I have a blog hosted freely on blogger. I want to show some html
I have this html file where I want to overlay some text over another.
I have an HTML page that contains some filenames that i want to download

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.