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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:52:08+00:00 2026-05-28T01:52:08+00:00

The following code adds the same ID to every div sibling: var d =

  • 0

The following code adds the same ID to every div sibling:

var d = 0;
var newid = currentId.substring(currentId.length-8, currentId.length-1)+d;

$.each(('table').next(), function() {
    $('table').find('div[id|="edid"]').attr("id", newid);   
    d++;
});

The HTML structure looks like this:

<table><tr><td><div id="edid-0-">text</div></td></tr></table>
<br>
<table><tr><td><div id="edid-0-">text</div></td></tr></table>
<br>
<table><tr><td><div id="edid-0-">text</div></td></tr></table>

After running my code, the IDs should look like: edid-0-0, edid-0-1, edid-0-2, and so on.

But instead, all are either edid-0-0, edid-0-0, did-0-0…
or edid-0-3, edid-0-3, edid-0-3…

depending on where i put the variables (in or outside the each function).

I tried various variations, but it’s always the same ID ending, und no continuing numberation. I kind of understand why this happens, but I have no clue on how solving this problem. Sitting here for hours. My head -> explodes.

  • 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-28T01:52:09+00:00Added an answer on May 28, 2026 at 1:52 am

    Since d is always 0, why dont you just use the index parameter in the function()

    Also, you are doing $("table") during each iteration, which will query the dom again. I assume you actually want $(this) which will find the <div/> under the current <table/>

    var newid = currentId.substring(currentId.length-8, currentId.length-1)+d;
    $.each($('table').next(), function(index, elm) {
        $(this).find('div[id|="edid"]').attr("id", newid + index);   
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code creates 3 buttons and adds a handler to each one. The
The following code adds a checkbox and a label to the calling node. My
I currently have the following code: import argparse parser = argparse.ArgumentParser(description='Adds a new modem
I have the following script that creates a div, adds a Google Maps DOM
I have the following tabs on certain div on my page: (this code is
In the following code, person.Children contains 3 other Person objects. This code adds the
The following code adds a class to a link and removes another class from
Writing a code that does the following: Adds a mouse listener to a web-page
The following jQuery code adds an event by calling a function scroll_position jQuery.event.add(window, scroll,
I have the following code which adds a label into a footer of a

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.