# Formatting background with cycle

**URL:** <https://discuss.rubyonrails.org/t/formatting-background-with-cycle/31803>\
**Category:** rubyonrails-talk\
**Created:** [July 14, 2008, 2:16am UTC](https://discuss.rubyonrails.org/t/formatting-background-with-cycle/31803 "2008-07-14T02:16:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 14, 2008, 2:16am UTC](https://discuss.rubyonrails.org/t/formatting-background-with-cycle/31803/1 "2008-07-14T02:16:09Z")

</div>

I've got a \<tr\> with onmouseout="this.style.background='\<%= cycle(odd-row, 'even-row')%\>';"

But that doesn't seem to work. onmouseover changes the bg to white, and I need to get the color back to its original color onmouseout.

The problem is the color is different for alternating rows.

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![Tonypm](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@Tonypm](https://discuss.rubyonrails.org/u/Tonypm)\
**Post date:** [July 17, 2008, 4:19pm UTC](https://discuss.rubyonrails.org/t/formatting-background-with-cycle/31803/2 "2008-07-17T16:19:34Z")

</div>

The result of your cycle will be a string, so the normal way to use this would be to assign the string to a class name, and then for each class, you define the background style you need in your stylesheet.

\<tr class="\<%= cycle("even", "odd") -%\>"\>

see [http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001928&name=cycle](http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001928&name=cycle).

If you want to build the whole style fro the cycle, it would need to be like this

style="background-color: \<%= cycle("#fff", "#ccc")

hth Tonypm
