Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.50/5 (3 votes)
See more:
hi...

how to create dynamic div in jquery and append a table in that div?
Posted

Try is as below :

C#
$("#foo").append("<div id='myDiv'>hello world</div>")

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

for(i=0; i<3; i++){
    var row = $('<tr></tr>').addClass('bar').text('result ' + i);
    table.append(row);
}

$('#myDiv').append(table);


More info : Create table with jQuery - append
 
Share this answer
 
 
Share this answer
 
Comments
anil.singh581 18-Jul-14 11:13am    
Nice link, helpful for me!! thanks
shyam ji 16-Aug-14 5:58am    
its good, thank you!!!
Put following code in your head tag

XML
<script type="text/javascript">
    $(document).ready(function () {

        $("#form1").append("<div style='width:100px;height:100px;background-color:red'>hello</div>").append("<table style='width:300px;height:100px;border: 2px solid blue'><tbody><tr><td style='border: 2px solid Red'>Row 1 Cell 1</td><td style='border: 2px solid Red'>Row 1 Cell 2</td></tr><tr><td style='border: 2px solid Red'>Row 2 Cell 1</td><td style='border: 2px solid Red'>Row 2 Cell 2</td></tr></tbody></table>")
    });
</script>

JavaScript




Remember i am using defualt form id as Form1 so replace it what ever you are having.
Do not forget to add jquery file

Hope This Helps!!!
 
Share this answer
 
Comments
Karthik_Mahalingam 30-Nov-13 11:06am    
this code is working fine...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900