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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:08:41+00:00 2026-06-06T22:08:41+00:00

I found a strange thing. When I insert an element into another with the

  • 0

I found a strange thing. When I insert an element into another with the jQuery html() method, the first element is removed from DOM. I want to know if it is possible to insert an element and keep it in DOM.

Here is an example:

$(document).ready(function(){
    select1 = $("#select-1");
    select2 = $("#select-2");
    $("#gap").html(select2); //Original select2 removed from DOM
});

As you can see the #select-2 element is no longer visible if it is inserted into another element. But I want to insert it, and keep the priginal element as before.

  • 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-06T22:08:42+00:00Added an answer on June 6, 2026 at 10:08 pm

    Assuming I’ve understood your question correctly, you can clone the element:

    $(document).ready(function(){
        var select1 = $("#select-1"),
            select2 = $("#select-2");
        $("#gap").html(select2.clone());
    });
    

    If you need to keep any event handlers that were bound to select2 you can pass true as an argument to clone.

    Here’s a working example.


    As a side note, notice that I’ve added the var keyword before your variable declarations. This prevents the variables from leaking into the global scope (which you usually don’t want).


    As another side note, it looks like this form of the html method is not documented in the jQuery API (it lists .html( htmlString ), and states that htmlString should be a “string of HTML”).

    The jQuery source however, clearly allows the use of a string, an element or a jQuery object. If htmlString is a string, the native innerHTML property is used. If not, the append method is used instead:

    if ( typeof value === "string" /* ... */ ) {
        //...
    }
    if ( elem ) {
        this.empty().append( value ); //In your case we end up here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found strange generics behaviour. In two words - thing I realy want is
during my debug sessions I found a strange thing occurring. I have an EditText
While searching a bug in my code today I found a strange thing. When
I found a very interesting/strange thing about MAX() function in SQL. I have column
Found very strange behavior of MS Access database when running queries from c#. It
I found strange thing. For example I have Order and Item entity. Item is
I found a strange thing in Python when I tried to compare lists composed
While studying the book Introduction to Algorithms by Cormen, I found a strange thing.
I tried many website with IE9. one strange thing I found is, when I
I found this strange thing. XCode instruments tell me that this line return (SDZPerson*)[[[SDZPerson

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.