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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:51:52+00:00 2026-06-15T07:51:52+00:00

PS: There were two answer before, and I refresh this page, the answer disappeared,

  • 0

PS: There were two answer before, and I refresh this page, the answer disappeared, what’s going on?

demo: demo in jsbin

html

<table>
<tr class='test_tr'>
  <td>
    <select class='test_select'>
      <option value=1>test1</option>
      <option value=2>test2</option>
      <option value=3>test3</option>
    </select>
  </td>
  <td><a href="#" class='test_clone'>clone</a></td>
</tr>

js

$(document).ready(function(){
  $('select.test_select').selectmenu();
  $('.test_clone').click(function(){
    var tp = $(this).parents('.test_tr');
    var new_tr = tp.clone(true);
    new_tr.insertAfter(tp);
    tr_func(new_tr);
  })
});
  function tr_func(new_tr){
     $('.test_select',new_tr).selectmenu();
  }

After click the clone button and click on the new select, it always affect to the first one.
Any suggestion? Thanks!

  • 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-06-15T07:51:54+00:00Added an answer on June 15, 2026 at 7:51 am

    This problem has a few interesting aspects:

    1. When a row is cloned, all items with an id attribute will be cloned as well, causing two elements with the same #ID; that’s not good. It can be solved by creating a pristine sample row that gets cloned every time you click the button which you then have to “decorate” before it can be used (i.e. apply .selectmenu() and click handler).

    2. When a <select> is cloned, it doesn’t retain the selected option. You have to save the selectedIndex property and apply it to the cloned version.

    Both problems solved looks like this:

      $(document).ready(function() {
        // keep reference to the sample row
        var sample = $('.test_tr.sample');
        // click handler for the clone button
        function cloneRow()
        {
          var parentRow = $(this).parents('.test_tr'),
              selectedOption = parentRow.find('.test_select').prop('selectedIndex');
    
          setupRow(newRow().insertAfter(parentRow), selectedOption);
        }
    
        // decorates the new row and sets the correct selected option before applying
        // selectmenu()
        function setupRow(row, selectedOption)
        {
          row
            .find('.test_select')
              .prop('selectedIndex', selectedOption || 0)
              .selectmenu()
              .end()
            .find('.test_clone')
              .click(cloneRow)
              .end()
        }
    
        // helper function that clones the sample and shows it before handing it over
        // to other code.
        function newRow()
        {
          return sample.clone().show();
        }
    
        // setup the first row
        setupRow(newRow().appendTo('table'));
      });
    

    Demo

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

Sidebar

Related Questions

There are two table s : one is the master and one the detail
There are two tables Table 1 select * from manage_tcp; +----+----------+--------+ | id |
I have asked this once before but i didnt get a very clear answer.
I know something like this has been asked before, but the answer was sort
not sure this was asked before, but I couldn't find an obvious answer. I'm
I know this has been asked before but I have looked at every answer
To preface, I've seen the command to answer this question before, but now I
There are some question which are related to this,. but getting the exact answer:
I have touched on this question in others before but after writing an answer
There are two similar questions asked here and here but no adequate answers are

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.