Change 'cell color' on dynamically added table cells

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsteiner
    New Member
    • Dec 2008
    • 25

    #1

    Change 'cell color' on dynamically added table cells

    Hi all
    On my web page I have a 3 column table.
    The first cell changes background color when mouseover event occurs.
    Something like this :
    Code:
    <TR><TD onMouseOver="this.bgColor='#00CC00'"
    onMouseOut="this.bgColor='#F0FFF0'" >name</TD>
    <TD>number</TD>
    <TD>address</TD><TR>
    This works fine.
    Problem starts when I add more rows dynamically to the table using:
    insertRow and insertCell
    I can't get the added cells to change their color too.
    I tried it like this:
    Code:
    row.cells[0].onmouseover="this.bgcolor='red'";
    Doesn't work.

    Can anybody help ?
    Thanks in advance
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Originally posted by nsteiner
    row.cells[0].onmouseover="t his.bgcolor='re d'";
    That piece of code is wrong, onmouseover expects a function, not a string. The correct way to do that would be:

    Code:
    row.cells[0].onmouseover = function() {
        this.style.backgroundColor = 'red';
    }

    Comment

    Working...