jQuery Table How to - Insert table to a div








Question

We would like to know how to insert table to a div.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<style type='text/css'>
tr:hover {<!--   w  w w. j  av  a 2  s  .c  o m-->
  background-color: #BADA55;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $(function () {
      $('#container').html('<table id="#tblResult"><tbody><tr><td>test</td><td>test</td></tr></tbody></table>');
    });
});
</script>
</head>
<body>
  <div id='container' />
</body>
</html>

The code above is rendered as follows: