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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:19:19+00:00 2026-05-20T17:19:19+00:00

So, say I have selected, in JQuery, a singular DOM div. I then proceed

  • 0

So, say I have selected, in JQuery, a singular DOM div.
I then proceed to create a new DIV like so:

var DIV = $("<div>Hello, world</div>");

After that, I attempt to place that DIV inside the original one like so:

$(OriginalDiv).append(DIV);

Okay, that works.
Now I want to edit DIV further.

Calls to .click, .html, .addClass, (And likely more) do not work!
Okay, instead I do:

var OriginalDiv = $("someSelector");
var DIV = $("<div>Hello, world</div>");
DIV = $(OriginalDiv).append(DIV);

That appears to work at first; However, instead, it sets DIV to reference the same DOM object as OriginalDiv and NOT the newly appended DOM object. Naturally, this does not allow me to edit DIV.

So, then, I try two more methods:

var OriginalDiv = $("someSelector");
var DIV = $("<div>Hello, world</div>");
$(DIV).appendTo(OriginalDiv);

and

var OriginalDiv = $("someSelector");
var DIV = $("<div>Hello, world</div>");
DIV = $(DIV).appendTo(OriginalDiv);

Not even these work.

If I haven’t done a very good job explaining, here is my exact dilemma

I am trying to create a DOM object in jquery, then append it to another DOM object using jquery. The problem is, once it gets appended, there seems to be no way for me to directly access it without using somethign like .children.

I’d like very much to be directly returned somewhere along in that process a reference to the DOM object which I am appending. As in the one that actually gets appended.

I’m not sure how to do this in JQuery. Anybody know a solution?

Thanks

–G

  • 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-20T17:19:20+00:00Added an answer on May 20, 2026 at 5:19 pm

    Yes, append won’t work as it returns a reference to the element the new element was appended to. jQuery supports method chaining, so this should work easily:

    $("<div>Hello, world</div>")
     .click(function() {
        // something
      })
     .appendTo('someSelector');
    

    But even

    var $ele = $("<div>Hello, world</div>").appendTo('someSelector');
    

    will work. appendTo returns a reference to the element which was appended. If this does not work for you, you have your problem elsewhere.


    Comments on your code: This is not your problem, however it is important for you to know what is going on here.

    This part

    var OriginalDiv = $("someSelector");
    var DIV = $("<div>Hello, world</div>");
    $(DIV).appendTo(OriginalDiv);
    

    is the same as

    $($("<div>Hello, world</div>")).appendTo($("someSelector"));
    

    You see, you have a nested call to jQuery, because DIV is already a jQuery object. There is no need to pass it again to jQuery.

    You can also pass a selector directly to appendTo.

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

Sidebar

Related Questions

Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say we have the following method: private MyObject foo = new MyObject(); // and
Say I have a class named Frog, it looks like: public class Frog {
Say I have 4 div elements with class .navlink , which, when clicked, use
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
Say you have an application divided into 3-tiers: GUI, business logic, and data access.
Say I have an ASMX web service, MyService. The service has a method, MyMethod.
Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
Say I have two strings, String s1 = AbBaCca; String s2 = bac; I
Say I have a Student table, it's got an int ID. I have a

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.