Jump to content

Modifying A Table?


davej

Recommended Posts

This is something I have not had any success with. What if you want to display a table and then in response to a button click you want to call a function that would grow the table? Thanks!

Link to comment
Share on other sites

Grow the table as how? Do u mean add <td> or <tr> tags(s) to the existing one(s)? If dats what you mean, here is an ex:

function growTB(theTable){tr=document.createElement('tr');td=document.createElement('td');td.settAttribute('style','width:200px; height:100px;')tr.appendChild(td);document.getElementById(theTable).appendChild(tr)}

The above, creates a new row, with a td inside.CALL

growTB('Table_ID')

Link to comment
Share on other sites

The problem is that you're going to have trouble because you're supposing there's no <tbody> element. The <tbody> element is required and the browser puts it whether or not it's in the code. Putting the <tr> as a direct child of the table in Javascript will not work right. It's best to use the insertRow() method of the table object and insertCell() method of the created row. Examples of usage are right there in the method descriptions.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...