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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:29:27+00:00 2026-05-28T07:29:27+00:00

I have a set of divs with the same class. I need to give

  • 0

I have a set of divs with the same class. I need to give each one an individual ID. And then apply that ID to the href of a link.

Here is the HTMl:

<div class="person-promo">
  <a href="***#ID-OF-SIBLING-DIV***" class="action">&gt; Read More</a>
  <div class="hide">
    <div id="***NUMBER-GOES-HERE***" class="person-details">
      <!-- -->
    </div>
  </div>
</div><!-- Person Promo -->

Each anchor needs to link to its sibling Div, if that makes sense.

I have been hunting around various sites, and the Jquery library for a few hours, but have had no luck. Just hoping for a bit help.

Thanks for everyone’s help by the way. It’s good to know SOME fellow developers will help each other out during difficulties. It is a great community on here.

  • 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-28T07:29:28+00:00Added an answer on May 28, 2026 at 7:29 am

    Easy enough:

    // Loop through the divs
    $(".person-promo .person-details").each(function(i) {
        // Store an id with format "uniqueId_{index}" in a variable.
        var id = "uniqueId_" + i;
        // Give the ID to the div
        $(this).attr("id", id);
        // Give it to the sibling link
        $(this).siblings("a").attr("href", "#" + id);
    });
    

    That said, you should probably generate all this server-side.

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

Sidebar

Related Questions

I have 1 div that will contain 3-5 divs with the same class. Below
I have a set of divs which are specified under the same class name,
I have a number of divs with the same class, that I want to
I have a set of divs all with the same class (they don't have
I have the following function set up to sequentially fade in divs (with class
I have a series of divs of the same class; some with title attributes
I have a set of divs that represent a set of fields. What I
Basically I have a set of divs that are pretty much identical in structure,
I have 4 divs that are set to float left but the end div
Doing some jquery animation. I have certain divs set up with an attribute 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.