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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:48:18+00:00 2026-05-13T19:48:18+00:00

I am facing an issue whlie trying to clone a parent div and then

  • 0

I am facing an issue whlie trying to clone a parent div and then appending it directly under itself. My function works fine as long as the last node is
selected so:

 <div>
 <div> A </div>
 <div> B </div>
 <div> C </div>
   </div>

will result in

<div>
 <div> A </div>
   <div> A.1 </div> 
 <div> B </div>
 <div> C </div>
   </div>

If i clone A. But if I clone A again I get.

<div>
 <div> A </div>
   <div> A.1 </div>
 <div> A </div>
   <div> A.1 </div>
 <div> B </div>
 <div> C </div>
   </div>

while I would like

<div>
 <div> A </div>
   <div> A.1 </div>
   <div> A.1 </div>
 <div> B </div>
 <div> C </div>
   </div>

My markup and code are below:

<div id="maindiv">
 <div>
  <label>First</label> 
  <input type="button" class="repeat1" onclick="Repeat(this)"/>
 </div>
 <div>
  <label>Second</label> 
  <input type="button" class="repeat1" onclick="Repeat(this)"/>
 </div>
 <div>
  <label>Third</label> 
  <input type="button" class="repeat2" onclick="Repeat(this)"/>
 </div>

</div>

function Repeat(obj)
{
 var CurrentDiv = $(obj).parents("div[class^='repeat']:first");
 $(CurrentDiv).clone().appendTo(CurrentDiv).end();

}

I also have a similar issue with deleting where all the child nodes are deleted while I just want a single div removed. Any help would be appreciated. The remove function is

function Remove(obj)
    {
     var CurrentDiv = $(obj).parents("div[class^='repeat']:first");
     CurrentDiv.remove();

    }
  • 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-13T19:48:19+00:00Added an answer on May 13, 2026 at 7:48 pm

    Is this what you are trying to do?

    function Repeat(obj)
    {
     var currentDiv = $(obj).parent("div");
     currentDiv.clone().insertAfter(currentDiv);
    }
    

    UPDATE:
    If you want nesting, try this:

    <div id="maindiv">
      <ul>First
       <li>
        <label>Sub-first</label> 
        <input type="button" class="repeat1" onclick="Repeat(this)"/>
       </li>
     </ul>
    
     <ul>Second
      <li>
       <label>Sub-second</label> 
       <input type="button" class="repeat1" onclick="Repeat(this)"/>
      </li>
     </ul>
    
     <ul>Third
      <li>
       <label>Sub-third</label> 
       <input type="button" class="repeat2" onclick="Repeat(this)"/>
      </li>
     </ul>   
    </div>
    
    <script>   
    function Repeat(obj)
      {
        var CurrentLi = $(obj).parent("li");
        CurrentLi.clone().insertAfter(CurrentLi);
      }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a class resolution issue while trying to make my architecture flexible.
I'm facing the same issue, while trying for cross-domain request. Situation is strange, my
I'm facing an issue with RestTemplate in Spring 3.0. When I'm trying to request
I am facing an issue while I am trying to deserialize a JSON array
I am facing an issue while trying to use the spring android framework. I
More precisely, I am facing this issue while trying to install https://github.com/barraponto/thacker-profile (commit 75c693581796eddae5fc39870dfcc2647e00c81b
I am facing an issue while trying to install the requirements for my django
I am facing this issue with the servlet when i am trying to stream
I am facing an issue while trying to reload rules dynamically. Starting with the
I am facing a strange issue while using javascript setTimeout function in IE8. I

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.