# Adding onmouseover to table rows through DOM (javascript)?

**URL:** https://forum.kirupa.com/t/adding-onmouseover-to-table-rows-through-dom-javascript/268840
**Category:** Uncategorized
**Created:** [August 19, 2008, 4:26pm UTC](https://forum.kirupa.com/t/adding-onmouseover-to-table-rows-through-dom-javascript/268840 "2008-08-19T16:26:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mlk](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mlk](https://forum.kirupa.com/u/mlk)
#### Post date: [August 19, 2008, 4:26pm UTC](https://forum.kirupa.com/t/adding-onmouseover-to-table-rows-through-dom-javascript/268840/1 "2008-08-19T16:26:37Z")

</div>

Hello guys.

I have the following problem:

I’ve generated a table through javascript using the appendChild method, and added at the same time unique row, column and cell IDs so I can easily fetch them later.

I’m trying to add (through a different loop) alternating row colors (easily done, it’s not the annoying bit) which change when onmouseover’ed .

Here’s my code (which doesn’t work)

```php
for(a=0;a<=20;a+=1){
		//m = (a % 2)*10;
		curRow = document.getElementById('rowRow'+a);
		curRow.onmouseover = function(){curRow.style.backgroundColor='rgb('+a*10+','+a*10+','+a*10+')'};
		curRow.onmouseout = function(){curRow.style.backgroundColor='#fefefe'};
		
}

```

Can you see what I’m doing wrong ?

Cheers

mlk

edit: I’ve posted a more complete explanation on [http://www.webdeveloper.com/forum/showthread.php?p=923013#post923013](http://www.webdeveloper.com/forum/showthread.php?p=923013#post923013) I’ll post the answer here if they answer faster. I’m still trying to figure it out.
