By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

Change 'cell color' on dynamically added table cells

P: 25
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 :
Expand|Select|Wrap|Line Numbers
  1. <TR><TD onMouseOver="this.bgColor='#00CC00'"
  2. onMouseOut="this.bgColor='#F0FFF0'" >name</TD>
  3. <TD>number</TD>
  4. <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:
Expand|Select|Wrap|Line Numbers
  1. row.cells[0].onmouseover="this.bgcolor='red'";
  2.  
Doesn't work.

Can anybody help ?
Thanks in advance
Jan 8 '09 #1
Share this Question
Share on Google+
1 Reply


xNephilimx
Expert 100+
P: 213
@nsteiner
That piece of code is wrong, onmouseover expects a function, not a string. The correct way to do that would be:

Expand|Select|Wrap|Line Numbers
  1. row.cells[0].onmouseover = function() {
  2.     this.style.backgroundColor = 'red';
  3. }
  4.  
Jan 8 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.