View Full Version : How to use DOM to control cellpadding/cellspacing???

10-04-2002, 11:11 AM
Is there a way to control cellpadding or cellspacing of a table using some form of the following code?:


Also, is there another form of this code that will eliminate just the top or bottom border of a table, maybe similar to this:

document.getElementsByTagName('table').item(5).topborder = "0"


10-04-2002, 01:04 PM
to eliminate top and bottom border:

document.getElementById('tbl').style.borderWidth='0px 2px 0px 2px'; //top right bottom left

to change cellpadding and cellspacing:


where tbl is the id of the table.

10-04-2002, 03:07 PM
Hello glenngv,

The cellPadding and cellSpacing work nicely, but I can't seem to get the following to work:

document.getElementsByTagName('table').item(5).style.borderWidth='0px 2px 2px 2px';

...to eliminate the top border. Do I have the syntax correct? For my application, I can't reference the table by ID, so I must find some way to use getElementsByTagName('table') instead of document.getElementById('tbl'). Can it be done?

:confused: :confused:

10-05-2002, 08:07 PM
not sure, but the way i know it is that it's just 'border', not 'borderWidth'

10-05-2002, 08:21 PM
oops, just checked it out. it's right, it works fine.

10-06-2002, 01:50 AM
ASAAKI, what works???!!! That's kinda vague. The following STILL isn't working for me, so what am I doing wrong?:

document.getElementsByTagName('table').item(5).style.borderWidth='0px 2px 2px 2px';

:confused: :confused: :confused:

10-06-2002, 11:25 AM
Originally posted by tired&lonely
document.getElementsByTagName('table').item(5).style.borderWidth='0px 2px 2px 2px';

is working fine with me... i don't know what it's got against u... :confused:

10-06-2002, 11:29 AM
the only thing i can think of is that u might have gotten the wrong item number... maybe forgotten that js starts with 0, so that would be item(4) not (5) .... sorry if i'm wrong..

10-06-2002, 10:23 PM
Thanks, glenngv & ASAAKI. It does work - I just had to move it down past the other code lines affecting that same table - weird.