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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:47:35+00:00 2026-05-27T13:47:35+00:00

Probably a common issue, but I’m looking for help in both fixing and understanding

  • 0

Probably a common issue, but I’m looking for help in both fixing and understanding the issue.

I’m making a form that allows you to add more fields. Here’s a stripped down version:

HTML

<div class="to_copy">
<p>Here is an empty form field.</p>
    <input name="input" />
</div>
<a href="#" id="copy">Copy</a>

jQuery

$(document).ready(function() {
    var to_copy = $(".to_copy").clone();

    $("#copy").on("click", function(e) {
       // Some unwritten code to change name="input" to name="input1"

       $(this).before(to_copy); 
       e.preventDefault();    
    });

});    

When you click copy, it works once, but not any more. If I check what’s going on, the to_copy variable has the correct value, and no errors are triggered.

Can anyone explain why it doesn’t work, as well as pointing me in the right direction.

My next stage is going to be to modify the names of the fields to have a number appended to them (i.e. input, input1, input2 etc), perhaps explaining why I’ve chose this approach.

Here’s a live version: http://jsfiddle.net/nGmYb/1/

  • 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-27T13:47:36+00:00Added an answer on May 27, 2026 at 1:47 pm

    The issue is that you’re attaching the clone to the DOM within the click event. On the second click you are re-adding the element to the DOM. Try the following instead:

    $(document).ready(function() {
        var to_copy = $(".to_copy").clone();
    
        $("#copy").on("click", function(e) {
            e.preventDefault();
            $(this).before(to_copy.clone());
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just ran across an issue that probably exposes my ignorance of common threading
I think I probably know that the most common suggestion will be change the
I'm a bit stuck on what is probably a common situation, but can't find
This is probably a very common question but here it goes. I created an
Probably a common problem, but anyway: Let's say I have a simple entity Task
This is probably a common question, but all answers on the internt have failed
I know this is probably a common and easily answered question, but I'm a
Ordering Java methods is probably the least important code style issue ever, but I'm
This is probably a common situation, but I couldn't find a specific answer on
Here's my situation, and it's probably fairly common but I have yet to find

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.