javascript - How to construct a complete HTML table using jQuery? -
i wish construct complete table using jquery.
i try learn or copycat question
but no luck.
what want create is
<table> <thead> <tr> <th>problem 5</th> <th>problem 6</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> </tr> </tbody> </table> the jquery code created is
var $table = $('<table/>'); var $thead = $('<thead/>'); $thead.append('<tr>' + '<th>problem 5</th>' + '<th>problem 6</th>' + '</tr>'; $table.append(thead); var $tbody = $('<tbody/>'); $tbody.append( '<tr><td>1</td><td>2</td></tr>' ); $table.append(tbody); $('#grouptable').append($table); but failed running.
can tell me why?
you missing right paren in $thead declaration:
$thead.append('<tr>' + '<th>problem 5</th>' + '<th>problem 6</th>' + '</tr>'); ^ and aren't appending variables correctly:
$table.append($thead); ^ $table.append($tbody); ^ here's working fiddle.
Comments
Post a Comment