views:

14

answers:

1

Hi all. Here is my code :

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    ;   "http://www.w3.org/TR/html4/loose.dtd"&gt;&lt;html&gt;
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
     </head>
    <body>
  <div id="divmenutable"></div>
  <script type="text/javascript">
   $(document).ready(function() {
    var menuTable = $("<table><table>").addClass("table_menu");
    var menuRow = $("<tr></tr>");
    var menuCol = $("<td>awef</td>");
    menuRow.append(menuCol);
    menuTable.append(menuRow);
    $("#divmenutable").append(menuTable);
   });
  </script>
    </body>
</html>

The result, div add table twice. I dont know why. My real code is to use 'for' loop to add data to table. I have minimized my code to show the problem. thank for your help.

+3  A: 

You are creating two tables. Close the end tag.

$('<table><table>').length // 2

Versus

$('<table></table>').length // 1

Could also do

$('<table/>')
meder
A good read about appending in jQuery: http://www.learningjquery.com/2009/03/43439-reasons-to-use-append-correctly
gearsdigital
Your last table doesn't require the end tag notation. $('<table>') works dandy in jQuery.
Stefan Kendall