append div to td in table dynamically

jquery

Solution

You need to append the `$wrap` object to the `<td>` element, not the `$table`.

Try something like this instead:

var $table = $('<table/>').addClass('commentbox');

$table.append('<tr><td>' + 'Comment Id:'+ '</td></tr>');

var $wrap = $('<div/>').attr('id', 'container');
var $in   = $('<input type="button" value="Reply"/>').attr('id', 'reply');

$wrap.append($in);

$table.append(
    $('<tr>').append($('<td>').append($wrap), $('<td>').html('hello'))
);

Demo here: http://jsfiddle.net/umCDP/

Problem

``` var $table = $('<table/>').addClass('commentbox'); $table.append('<tr><td>' + 'Comment Id:'+ '</td></tr>'); var $wrap = $('<div/>').attr('id', 'container'); var $in = $('<input type="button" value="Reply"/>').attr('id', 'reply'); $wrap.append($in); $table.append( $('<tr>') .append($('<td>'), $('<td>')) ); $table.append($wrap); ``` I want the div id container to be added inside td but I am getting html ``` <table> <tbody> <tr> <td>Comment</td> </tr> <tr> <td> </td><td></td> </tr> <tbody> <div id="container"> <input type="button" value="Reply" id="reply"> </div> </table> ```

Original source

Related problems