harry wrote:
I want to be able to change the text alignment within a table cell between
"right" & "center" depending on how many rows are in the table.
Is this possible in Javascript?
In browsers that implement the W3C DOM HTML module as specified here
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075>
table cell element objects have property named align which you can read
and set e.g.
tableCell.align = 'right';
Table element objects as documented here
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-64060425>
have a rows property whiich is a collection with a length property so
you could check
if (tableElement.r ows.length > 200) {
tableCell.align = 'right';
}
Getting a table or table cell elements can be done in various ways, by
id e.g.
<table id="table1">
<tbody>
<tr>
<td id="cell1">... </td>
...
...
</table>
var tableElement, tableCell;
if (document.getEl ementById) {
tableElement = document.getEle mentById('table 1');
tableCell = document.getEle mentById('cell1 ');
// then do above check here
}
but of course the DOM offers various other possibilities (e.g.
document.getEle mentsByTagName( 'table')) to find elements.
Support for that is in at least IE5+, Netscape 6+, Mozilla 1.x, Opera 7,
hopefully in Safari and Konqueror too though I am not sure there I have
ever tested to manipulate the align property of a table cell.
--
Martin Honnen
http://JavaScript.FAQTs.com/