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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:40:33+00:00 2026-06-11T18:40:33+00:00

I have a number of div elements with three class names each. There is

  • 0

I have a number of div elements with three class names each. There is an image inside each one. They’re consecutively numbered (i1, i2, i3…) through class names. The class names are something like "img small i14". I need to increment the numbers of these class names for each element.

So: for each of these div elements I need to change the class starting with i – add 1 or subtract 1 from it. Hopefully there is an efficient way of doing this.

The goal of the whole thing is to create a rotating image gallery. I’d much appreciate help, either through helping with the code or offering a better way of approaching the problem. Thank you.

  • 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-11T18:40:35+00:00Added an answer on June 11, 2026 at 6:40 pm

    If you combine Pointy’s regExp with undefined’s jQuery attribute setter you get this:

    $(a selector).attr('class', function (index, attrValue) {
        return attrValue.replace(/\bi(\d+)\b/, function (match, $1) { 
            return 'i' + (Number($1) + 1);
        });
    });
    

    Which works fine (cross browsers i suppose), since the class is an html attribute.

    EDIT: To check whether it’s the last image or not you’ll have to know how many images it is in that container, so you’ll have to have a jquery selector that just matches the images in one of the containers.
    The code would look like this:

    var number_of_elements = $(the selector).length;
    
    $(the selector).attr('class', function (index, attrValue) {
        return attrValue.replace(/\bi(\d+)\b/, function (match, $1) { 
            var number = Number($1);
            if (number === number_of_elements) {
                return 1
            } else {
                return 'i' + (number + 1);
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have three button elements in one parent div. Assuming that these
I have a number of classes and they are quite close to each other
I have a number of classes (more than 40), each one has a number
I have a scrollable div element with a number of checkboxes dynamically generated. I
I have a div which contains a number of images. I would like to
Hey guys quick question. I have a div that gets assigned a number to
I have my html containers as follows and it has number of levels. <div
I have 2 elements ( div ) : I <div id=1> <div > <img
Folks, Let's say that I have the following situation: <div class=outer> <div> <span> <ul>
I have a DOM element (#installations) with a number of children, only one of

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.