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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:40:26+00:00 2026-05-26T21:40:26+00:00

I am trying to clone DIV and it’s inner elements. How can I change

  • 0

I am trying to clone DIV and it’s inner elements. How can I change the names of all inner elements? Also I have function calls on the radio buttons. I need to change the name of the function also.Here is my HTML code. I appreciate any help.

<div id="clonableDiv">
    <input id="radio_1" type="radio1" onclick="toggleNames1()" value="Yes" name="Yes">
    Yes
    <br>
    <input id="radio_2" type="radio1" onclick="toggleNames2()" value="No" name="No">
    No
    <div id="address">Address:</div>
    <div id="address1">
        <input id="address_1" class="textBox" type="text" maxlength="100" name="address_1">
    </div>
    <div id="country_select">
        Country:
        <select id="country_drop_1" name="country_drop_1" onchange="setCountry(this.selectedIndex)"> 
            <option value="-1"></option>
            <option value="USA">USA</option>
            <option value="Canada">Canada</option>
        </select>
    </div>
</div>
  • 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-26T21:40:26+00:00Added an answer on May 26, 2026 at 9:40 pm

    Here’s a way to clone that div, update all the IDs and names and then insert the clone into the body:

    var cloneCntr = 1;
    function makeClone() {
        // clone the div
        var clone = $("#clonableDiv").clone(false);
        // change all id values to a new unique value by adding "_cloneX" to the end
        // where X is a number that increases each time you make a clone
        $("*", clone).add(clone).each(function() {
            if (this.id) {
                this.id = this.id + "_clone" + cloneCntr;
            }
            if (this.name) {
                this.name = this.name + "_clone" + cloneCntr;
            }
        });
        ++cloneCntr;
        $(document.body).append(clone);                         
    
    }
    

    To update the onclick handlers, you can just assign new values to them with obj.onclick = fn;.

    You can see it in action here: http://jsfiddle.net/jfriend00/r2RLw/.

    Much of this fixup of the clone would not be needed if you didn’t use ID values and only used class names, but if this is part of a form that is getting submitted so you need unique name values, then you will have to do this type of fixed after cloning.

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

Sidebar

Related Questions

I'm trying to use git on windows to clone a remote repository. I can
hope can help, trying out Jquery clone which seems to work, but I get
I'm trying to write a "blinds" function that would close a DIV in a
I am facing an issue whlie trying to clone a parent div and then
i'm trying to have 3 levels of lists all of which are sortable &
I am trying to clone an element, and then traverse through it's child elements
I'm trying to clone my personal fork on github using the git+ssh protocol with
Im trying to get a completly data copy from a gridview, itryed clone(), tryed
I'm using Isapi Rewrite 3 (mod rewrite clone for IIS) and trying to rewrite
Here's the deal. I'm trying to write an arkanoid clone game and the thing

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.