472,958 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Change table cell text alignment?

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? - can't see how to do it!


Jul 23 '05 #1
3 16124

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
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
have a rows property whiich is a collection with a length property so
you could check
if (tableElement.rows.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">
<td id="cell1">...</td>

var tableElement, tableCell;
if (document.getElementById) {
tableElement = document.getElementById('table1');
tableCell = document.getElementById('cell1');
// then do above check here
but of course the DOM offers various other possibilities (e.g.
document.getElementsByTagName('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
Jul 23 '05 #2
Martin Honnen wrote:
if (tableElement.rows.length > 200) {
tableCell.align = 'right';

You can also play with the style object:

if (tableElement.rows.length > 200 && tableCell.style) {
tableCell.style.textAlign = 'right';
// more style manipulation

Jul 23 '05 #3
You might also be able to put a div tag inside each cell with a class
on it that will hold your content. Then, it would be really easy to
dynamically change the class using javascript.

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Pete Kipe | last post by:
I'm not a JavaScript programmer...but I'm trying to put together a simple menu system for a new website and need a little help. I have the following script: <SCRIPT language=javascript> <!--...
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
by: Mark A. Sam | last post by:
Hello, Whenever I add a table, the text position of the cells is centered. I would like the default to be left-top. Is there a way to set this? Thank you and God Bless, Mark A. Sam
by: charles-brewster | last post by:
I'm trying to write a simple JavaScript function which will use a button to copy table cell data into a form input text box as the "value" attribute. The following is intended to test the...
by: charles-brewster | last post by:
I have progressed the copytext function test page a little since my original post here in the small hours this morning. It now opens a debugging window so I can try to figure out what it is or...
by: Daniel Kabs | last post by:
Hello there again! On my quest to remove layout tables in favor of CSS controlled elements, I am faced with quite a problem. A table cell that has no explicit width attribute set usually...
by: nino9stars | last post by:
Hello, I have just started messing with absolute positioning on webpages, and it definitely let's you do some creative things. Well, after much searching and help, I got the images I was using...
by: mridul | last post by:
I have a html which contains a table. As the data comes dynamically so the table cells expand and contract accordingly.To stop it i have fixed the width of table cells(td). But in one table cell a...
by: asafok | last post by:
hi, i'm tring to get access to a cell inside a table that has the vlaue of an Email address but is not clickable. i tring to go to that cell and Wrap the inner text with <a href="mailto... tag so...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.