...

View Full Version : Possible to create TH element using insertCell?



lunaport
12-13-2004, 05:33 PM
It appears that using the insertCell method to append a cell to a table row in the tbody creates a data cell by default. I need to create a header cell (in the tbody, not in the thead). Is this possible?

The desired result would be something like this:


<table>
<tbody>
<tr>
<th>#text</th> <-- I am unable to create this element.
<td>#text</td>
<td>#text</td>
</tr>
</tbody>
</table>

hemebond
12-13-2004, 10:43 PM
It doesn't look like it. You'll have to createElement.

Kor
12-16-2004, 10:48 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function createTh(){
var root= document.getElementById('tab').getElementsByTagName('tr')[0];
var eTh = document.createElement('th');
var eTxt = document.createTextNode('#text');
var ref = root.getElementsByTagName('td')[0];
eTh.appendChild(eTxt);
root.insertBefore(eTh,ref);
}
onload=createTh;
</script>
</head>
<body>
<table id="tab">
<tbody>
<tr>
<td>#text</td>
<td>#text</td>
</tr>
</tbody>
</table>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum