Mikebert4
09-04-2008, 10:39 AM
Ok, I've got a simple HTML page (DEMO HERE (http://www.nefariousguild.co.uk/tableDemo)).
The resetTable Demo button fires this function:
function resetTerrTable()
{
var title_arr = ["Territory","Availability","Style","Group","Label"]; //array of titles
if ( terrs.hasChildNodes() ){
while ( terrs.childNodes.length >= 1 ){
terrs.removeChild( terrs.firstChild );
}
} //clear the territories table
var titlebar = document.createElement("tr"); //create first <TR> element
for(i=0; i<title_arr.length; i++)
{
var title = document.createElement("th");
if(document.all){
title.innerText = title_arr[i];
}else{
title.textContent = title_arr[i];
}
titlebar.appendChild(title);
} //populate it with titles from the array
terrs.appendChild(titlebar); //write out first row
}
and the HTML on the page looks like this:
<body>
<input type="button" value="resetTable" onclick="resetTerrTable()">
<table id="territories">
<tr>
<th>Territory</th>
<th>Availability</th>
<th>Style</th>
<th>Group</th>
<th>Label</th>
</tr>
<tr>
<td colspan="5">Random Data that gets removed when you reset table</td>
</tr>
</table>
<script type="text/javascript">
<!--
var terrs = document.getElementById("territories");
//-->
</script>
</body>
I've two questions:
1. Why does the table 'expand' by 1 pixel when resetTerrTable() is fired in Firefox?
2. Why doesn't the DOM work in IE?
I've tried writing the titlebar element to the document before giving it children, thus:
function resetTerrTable()
{
var title_arr = ["Territory","Availability","Style","Group","Label"]; //array of titles
if ( terrs.hasChildNodes() ){
while ( terrs.childNodes.length >= 1 ){
terrs.removeChild( terrs.firstChild );
}
} //clear the territories table
var titlebar = document.createElement("tr"); //create first <TR> element
titlebar.setAttribute("id","titlebar");
terrs.appendChild(titlebar); //write out first row
for(i=0; i<title_arr.length; i++)
{
var title = document.createElement("th");
if(document.all){
title.innerText = title_arr[i];
}else{
title.textContent = title_arr[i];
}
document.getElementById('titlebar').appendChild(title);
} //populate it with titles from the array
}
I'm more than a little stumped with this, can anyone help?
Many thanks,
Mike
The resetTable Demo button fires this function:
function resetTerrTable()
{
var title_arr = ["Territory","Availability","Style","Group","Label"]; //array of titles
if ( terrs.hasChildNodes() ){
while ( terrs.childNodes.length >= 1 ){
terrs.removeChild( terrs.firstChild );
}
} //clear the territories table
var titlebar = document.createElement("tr"); //create first <TR> element
for(i=0; i<title_arr.length; i++)
{
var title = document.createElement("th");
if(document.all){
title.innerText = title_arr[i];
}else{
title.textContent = title_arr[i];
}
titlebar.appendChild(title);
} //populate it with titles from the array
terrs.appendChild(titlebar); //write out first row
}
and the HTML on the page looks like this:
<body>
<input type="button" value="resetTable" onclick="resetTerrTable()">
<table id="territories">
<tr>
<th>Territory</th>
<th>Availability</th>
<th>Style</th>
<th>Group</th>
<th>Label</th>
</tr>
<tr>
<td colspan="5">Random Data that gets removed when you reset table</td>
</tr>
</table>
<script type="text/javascript">
<!--
var terrs = document.getElementById("territories");
//-->
</script>
</body>
I've two questions:
1. Why does the table 'expand' by 1 pixel when resetTerrTable() is fired in Firefox?
2. Why doesn't the DOM work in IE?
I've tried writing the titlebar element to the document before giving it children, thus:
function resetTerrTable()
{
var title_arr = ["Territory","Availability","Style","Group","Label"]; //array of titles
if ( terrs.hasChildNodes() ){
while ( terrs.childNodes.length >= 1 ){
terrs.removeChild( terrs.firstChild );
}
} //clear the territories table
var titlebar = document.createElement("tr"); //create first <TR> element
titlebar.setAttribute("id","titlebar");
terrs.appendChild(titlebar); //write out first row
for(i=0; i<title_arr.length; i++)
{
var title = document.createElement("th");
if(document.all){
title.innerText = title_arr[i];
}else{
title.textContent = title_arr[i];
}
document.getElementById('titlebar').appendChild(title);
} //populate it with titles from the array
}
I'm more than a little stumped with this, can anyone help?
Many thanks,
Mike