# Insert\_html and cycle()

**URL:** <https://www.ruby-forum.com/t/insert-html-and-cycle/119588>\
**Category:** Rails\
**Created:** [November 8, 2007, 7:10am UTC](https://www.ruby-forum.com/t/insert-html-and-cycle/119588 "2007-11-08T07:10:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Swasey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@Matthew\_Swasey](https://www.ruby-forum.com/u/Matthew_Swasey)\
**Post date:** [November 8, 2007, 7:10am UTC](https://www.ruby-forum.com/t/insert-html-and-cycle/119588/1 "2007-11-08T07:10:24Z")

</div>

Has anyone here ever run into the problem of having a list that cycles  
a class name, in order for alternating lines to have a different  
color, using the cycle() helper, but had it mess up when using the  
prototype/ajax helper insert\_html?

I’m trying to come up with a solution for this, and this is what I  
have so far.

I’ve got a javascript that is included in the page:

Event.observe(window, ‘load’, function(){

var alternateColor = function(){  
$$(‘li.item’).each(function(el, index){  
if (index % 2)  
el.addClassName(‘alternate’);  
});  
};

alternateColor();  
});

And in my form\_remote\_for, I use the callback “complete” like this:

form\_remote\_for(:model, :url =\> example\_path, :complete =\>  
“alterateColor()”) do |f|

The problem is, while the javascript works when reloading the page, it  
fails to do anything after the form is submitted and the Ajax call is  
made.

---

<div class="post-metadata">

**Author:** ![Matthew\_Swasey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@Matthew\_Swasey](https://www.ruby-forum.com/u/Matthew_Swasey)\
**Post date:** [November 8, 2007, 8:17am UTC](https://www.ruby-forum.com/t/insert-html-and-cycle/119588/2 "2007-11-08T08:17:08Z")

</div>

form\_remote\_for(:model, :url =\> example\_path, :complete =\>  
“alterateColor()”) do |f|

Try changing alterateColor() to alternateColor() there?
