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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:01:06+00:00 2026-06-17T18:01:06+00:00

I am using jQuery 1.9.0 , and my html is: <div id=’div1′> </div> <div

  • 0

I am using jQuery 1.9.0, and my html is:

<div id='div1'>    
</div>
<div id='div2'>
</div>

my js:

var input = $("<input type='text'>");
$('#div1').html(input);
$('#div2').html(input);

my understanding of this code is

input is a jQuery object, and I can set div1 and div2 with it separately just like I can assign one variable’s value to many other variables in programming languages.

based on this understanding, what I expect is:

<div id='div1'>
    <input type="text">
</div>
<div id='div2'>
    <input type="text">
</div>

but I get:

<div id='div1'>
</div>
<div id='div2'>
    <input type="text">
</div>

if I just call $('#div1').html(input);, div1 would have input element.
why does div1‘s input element disappear after calling $('#div2').html(input);?

I know how to bypass this problem, but I am eager to know the reason of this behavior.

thanks in advance!

UPDATE:

I appreciate all the guys who answered this problem sincerely, and I have voted up every answer. I have a clue to this issue now, but I am still wondering why different nodes (div1 and div2) can not reference to the same object. In C language, different variables can reference to the same memory address. what’s the difference between these two reference?

  • 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-17T18:01:08+00:00Added an answer on June 17, 2026 at 6:01 pm

    The bottom line is that the DOM doesn’t automatically clone your elements when you attach them somewhere on the page. This is not jQuery specific.

    Because input keeps referencing the same element, attaching input to another element later on will detach it from the previous location, thus input keeps moving around in the DOM.

    This is why you have to clone the element before you attach it 🙂

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

Sidebar

Related Questions

Finding closet div (in next column of a table) using jquery <td><input type=text name=username
Suppose the following HTML div container <div id=container> <form> <div> <label class=error>Name</label> <input type=text
I'm using JQuery to set the HTML inside a div. Something like this: $(div).html(strHtmlBlob);
How to remove using jquery html table row after checking checkbox that in this
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
How can I get DIV id or DIV class using Jquery if the HTML
Hi i have to add a code in html using Jquery html(), the problems
I am getting my current page HTML using Jquery's .html() method like this. <h:outputScript
I am using JQuery to insert HTML in my DIV element I have the
I have this Javascript below using jQuery that shows a div on a page

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.