Jump to content

Recommended Posts

I'm trying to create a simple form that allows the user to add another item when they click a button. Here is my HTML:

<div class="row led-item">
   <div class="form-group col-10">
      <label for="exampleFormControlSelect1">Product</label>
      <select class="form-control" id="exampleFormControlSelect1">
         <option>1</option>
         <option>2</option>
         <option>3</option>
         <option>4</option>
         <option>5</option>
      </select>
   </div>
   <div class="form-group col-2">
      <label for="exampleFormControlInput1">Quantity</label>
      <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
   </div>
</div>

My JS:

//add item to request leds forms
$('#request-leds-add-item').click(function() {
    $('.led-item:first').clone().appendTo('.led-item');
});

But instead of it cloning the .led-item and inserting it after the first instance of it; it inserts it into the the first instance of .led-item like so:

<div class="row led-item">
   <div class="form-group col-10">
      <label for="exampleFormControlSelect1">Product</label>
      <select class="form-control" id="exampleFormControlSelect1">
         <option>1</option>
         <option>2</option>
         <option>3</option>
         <option>4</option>
         <option>5</option>
      </select>
   </div>
   <div class="form-group col-2">
      <label for="exampleFormControlInput1">Quantity</label>
      <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
   </div>
   <div class="row led-item">
      <div class="form-group col-10">
         <label for="exampleFormControlSelect1">Product</label>
         <select class="form-control" id="exampleFormControlSelect1">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
         </select>
      </div>
      <div class="form-group col-2">
         <label for="exampleFormControlInput1">Quantity</label>
         <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
      </div>
   </div>
</div>

 

Link to comment
https://forums.phpfreaks.com/topic/311457-jquery-clone/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.