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

  • Home
  • SEARCH
  • 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 720095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:43:09+00:00 2026-05-14T05:43:09+00:00

clone.find(‘[id]’).each(function() { id = $(this).attr(‘id’); ind = id.search(/\d+$/); $(this).attr(‘id’, id.substr(0,ind)+id_counter); }); clone.find(‘[for]’).each(function() { id

  • 0
    clone.find('[id]').each(function() {
        id = $(this).attr('id');
        ind = id.search(/\d+$/);
        $(this).attr('id', id.substr(0,ind)+id_counter);
    });
    clone.find('[for]').each(function() {
        id = $(this).attr('for');
        ind = id.search(/\d+$/);
        $(this).attr('for', id.substr(0,ind)+id_counter);
    });

I know I can find elements that have either the id attribute or the for attribute, but then how do I know which one I need to set?

  • 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-14T05:43:10+00:00Added an answer on May 14, 2026 at 5:43 am

    If all you’re trying to do is reduce code, you could…

     function doTheseThings(element) {
        clone.find(element).each(function() {
           var id = $(this).attr('id');
           var ind = id.search(/\d+$/);
           $(this).attr('id', id.substr(0,ind)+id_counter);
        });
     }
    
     doTheseThings('[id]');
     doTheseThings('[for]');
    

    EVEN BETTER:

    I decided to meld my first answer with some of @SHiNKiROU’s ideas and add some more Jquery-ish syntax:

    var items = ['[id]', '[for]'];
    $.each(items, function (index, element) {
        clone.find(element).each(function() {
           var id = $(this).attr('id');
           var ind = id.search(/\d+$/);
           $(this).attr('id', id.substr(0,ind)+id_counter);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, I can't get .attr('checked', false) to work on IE6. I
I'm going through Bitbucket and I can't seem to find any Mercurial repositories that
I haven't been able to find anything about this value error online and I
I am using a jQuery function to clone a DIV that contains a set
EDITED : The problem is with the function 'find_callback', I want to insert each
When you do your first clone using the syntax git clone username@server:gitRepo.git Is it
I'm trying to find a way to copy a schema under a different name.
I'm currently trying to use the jquery find method on an object twice but
There are heaps of examples of how to clone a Lua table in Lua,
I'm making a jquery clone for C#. Right now I've got it set up

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.