creating a 2 column table dynamically using jquery

Posted by user1908568 on Stack Overflow See other posts from Stack Overflow or by user1908568
Published on 2014-06-10T14:58:27Z Indexed on 2014/06/10 15:24 UTC
Read the original article Hit count: 112

Filed under:
|

I am trying to generate a table dynamically using ajax call. To simplify things i have just added my code to js fiddle here -> http://jsfiddle.net/5yLrE/81/

As you click on the button "HI" first two columns are created properly.. but some how as the td length reaches 2 . its not creating another row. The reason is that when i do find on the table elements its actually retrieving the children table elements. Can some one pls help.

I want a two column table.. Thank you.

sample code:

var tr = $("#maintable tbody tr:first");

if(!tr.length || tr.find("td:first").length >= max) {
    $("#maintable").append("<tr>");
}
if(count==0) {
    $("#maintable tr:last").append("<td>hi"+content+"</td>");
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery