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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:09:25+00:00 2026-05-23T06:09:25+00:00

how to copy an object with some elements? I want to copy this object,

  • 0

how to copy an object with some elements?

I want to copy this object, but each elm still refers to the same DOM element?

var fields = {
    account_id_ : {
        name : Lang.get('HDL_ACCOUNT'),
        width : 60,
        elm : $('<input class="inp" type="text" style="text-align:right" />'),
        value : '',
        focus : true
    },
    name : {
        name : Lang.get('HDL_NAME'),
        width : null,
        elm : $('<input class="inp" type="text" />'),
        value : ''
    }
};
  • 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-23T06:09:26+00:00Added an answer on May 23, 2026 at 6:09 am

    You can just loop through and .clone() the jQuery object (and the elements, 1 in this case, that it references. A very concise method would look like this:

    var fields2 = $.extend(true, {}, fields);
    $.each(fields2, function(n, f) { f.elm = f.elm.clone(); });
    

    Now fields2 has it’s own elements, you can test it here, compare it to here which doesn’t run the clone line, and references/re-appends the same elements, instead of clones in the first example.

    For clarity, a raw javascript version of the clone loop would look like this:

    for(var fieldName in newFields) {
        var field = newFields[fieldName];
        if(field .hasOwnProperty("elm"))
            field.elm = field.elm.clone();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a Deep Copy of some Object[] and ArrayList How can
I have some code that performs a deep copy using Object.clone, but I'm trying
Example code: jQueryElement.append(jQueryOtherElement.remove(#some-selector)) Will this make a copy of my element and append it
I want to add unique ID (within a single session) to each object of
I want to be able to iterate over a queue, each time adding some
I want to take each element within a qstringlist and get the raw data
Suppose I have a class, and I want to reference some elements in the
Say you in JavaScript are handed a single DOM element or Document (for example
I took a method from this post (accepted answer code) that serializes object so
Suppose that you're given an array A of n distinct elements drawn from some

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.