Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to use DOM to control cellpadding/cellspacing???

    Is there a way to control cellpadding or cellspacing of a table using some form of the following code?:

    document.getElementsByTagName('table').item(#)...

    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"


  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    to eliminate top and bottom border:

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

    to change cellpadding and cellspacing:

    document.getElementById('tbl').cellPadding='2px'
    document.getElementById('tbl').cellSpacing='3px'

    where tbl is the id of the table.

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not sure, but the way i know it is that it's just 'border', not 'borderWidth'
    'If you don't stand for something, you'll fall for anything.'

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oops, just checked it out. it's right, it works fine.
    'If you don't stand for something, you'll fall for anything.'

  • #6
    New Coder
    Join Date
    Aug 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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';


  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    'If you don't stand for something, you'll fall for anything.'

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..
    'If you don't stand for something, you'll fall for anything.'

  • #9
    New Coder
    Join Date
    Aug 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, glenngv & ASAAKI. It does work - I just had to move it down past the other code lines affecting that same table - weird.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •