How to grab and return a Div with its Id included

Seems like a super simple question but I can't find an answer.

I'm grabbing a DIV "user-entry"

var $user = $('#user-entry');

HTML:

<div id="user-entry">

<table style="border: none; width: 100%">
            <thead>
                <tr>
                    <th colspan="2" style="text-align: left">
                        @Html.Label("Hello World")
                    </th>
                </tr>
            </thead>
    </table>
</div>

Now I want to append this to another div <div id="role"></div>. That's what JQuery append(), appendTo(), prepend(), prependTo() functions are for. Great!

My problem is that when used the DIV is being added without the actuall DIV name. If example run:

            var $user= $('#user-entry');
            $($user.html()).appendTo('#role');

Then my table is being properly appended to the "role" but the user DIV itself doesn't show.

Instead of:

<div id="role">
   <div id="user-entry">
      <table style="border: none; width: 100%">
     </table>
   </div>
</div>

I end up with:

<div id="role">
      <table style="border: none; width: 100%">
     </table>
</div>

How can I capture and return a div with its name Included ?

Answers


This is the correct way to do it

$('#user-entry').appendTo('#role');

$($user.html()).appendTo('#role'); creates a copy of the elements inside <div id="user-entry"> and appends them to <div id="role">


because by using html method you are only appending the contents of the div, try this:

$('#user-entry').clone().appendTo('#role')

DEMO


Try:

$('#user-entry').appendTo('#role');

Or if you want to clone it try:

$('#user-entry').clone().appendTo('#role')

Need Your Help

Retrieve comments on Facebook ads through the API

facebook facebook-graph-api facebook-ads-api

Is it even possible to retrieve comments on Facebook ads through the API (Graph or FQL)? If yes, do I need a whitelisted app to do it? Also, if I have a page access token, is it enough, or I need a...

Efficient Fast Color Extraction Emgucv

performance colors tracking emgucv hsv

So I'm new to image processing, and i'm kinda learning emgucv right now..