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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Setting table cell style attributes

    given a cell from a table...
    function Tbl_GetCell(tbl, row, col)
    {
    var theRow = tbl.getElementsByTagName("tr")[row];
    return theRow.getElementsByTagName("td")[col];
    }

    I can set attributes like width, height, and align, but how can I set cell style info?

    cell = GetCell(tbl,row,col)
    these work fine... cell.align = "center"; cell.height = 22;
    but this doesn't... cell.style = "font-weight: bold; text-decoration: blink"

    help?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,045
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    cell.style.fontWeight = "bold";
    cell.style.textDecoration = "blink";
    But it's better to just set the CSS classname so that the code is shorter and all the properties are set at once.
    Code:
    <style type="text/css">
    .test {
      font-weight: bold;
      text-decoration: blink;
      /*...and so on*/
    }
    </style>
    Code:
    cell.className = "test";

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thanks glenn. amazing how the simplest stuff is sometimes so hard to find. you're my hero. thanks again.


  •  

    Posting Permissions

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