-2

I have my html code like

<html>
<table>
   <tr>
      <td id="table_td">div here</td>
   </tr>
</table>
<div id="table_div">
    Hello
</div>
</html>

Expected is i need to add "table_div" to " table_td" dynamically

<html>
<table>
   <tr>
      <td id="table_td">
          <div id="table_div">
              Hello
          </div>
      </td>
   </tr>
</table>
Nick
  • 51
  • 1
  • 8
  • This should work `$('#table_td').append($('#table_div'))`. – abhishekkannojia Mar 21 '17 at 12:42
  • [`document.querySelector()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) + [`Node.appendChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild) – Andreas Mar 21 '17 at 12:42
  • Possible duplicate of http://stackoverflow.com/questions/11152315/can-i-append-an-already-existing-div-to-another-already-existing-div – shubham agrawal Mar 21 '17 at 12:43
  • http://api.jquery.com/append or http://api.jquery.com/appendto – Rory McCrossan Mar 21 '17 at 12:45
  • Possible duplicate of [Can i append an already existing div to another already existing div?](http://stackoverflow.com/questions/11152315/can-i-append-an-already-existing-div-to-another-already-existing-div) – TrampolineTales Mar 21 '17 at 12:46

2 Answers2

0

I think that what you are looking for is jQuery .append() there is also .appendTo()

$( "#table_td" ).append( "<div id='table_div'>Hello</div>" );

For more details: http://api.jquery.com/append/

0
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>clone demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

  <b>Hello</b><p>, how are you?</p>

 <script>
   $( "b" ).clone().prependTo( "p" );
 </script>

Richardson. M
  • 852
  • 2
  • 17
  • 28