# Formatting background with cycle

**URL:** <https://www.ruby-forum.com/t/formatting-background-with-cycle/142971>\
**Category:** Rails\
**Created:** [July 14, 2008, 4:16am UTC](https://www.ruby-forum.com/t/formatting-background-with-cycle/142971 "2008-07-14T04:16:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 14, 2008, 4:16am UTC](https://www.ruby-forum.com/t/formatting-background-with-cycle/142971/1 "2008-07-14T04:16:09Z")

</div>

I’ve got a

 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:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 17, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/formatting-background-with-cycle/142971/2 "2008-07-17T18:19:54Z")

</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.

 "\>

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
