javascript - How to construct a complete HTML table using jQuery? -


i wish construct complete table using jquery.

i try learn or copycat question

create table jquery - append

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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -