O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appending Rows to a Table

var newRow = $("<tr></tr>"); var newCell = $("<td>cel1</td>"); newRow.append(newCell); $("tbody").append(newRow):

A common task when dynamically manipulating web pages is to add rows to elements in a table. To add rows to a table, you need to create a new <tr> element and then add the <td> elements. For example:

var newRow = $("<tr></tr>"); var newCell = $("<td>cel1</td>"); newRow.append(newCell); $("tbody").append(newRow):

The following example illustrates using table building using a series of arrays to populate the data. The buildTable() function selects a random item out of the arrays to be placed into the <td> elements. Figure 10.4 shows the final ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required