# RJS, select, & replace\_html

**URL:** <https://www.ruby-forum.com/t/rjs-select-replace-html/178880>\
**Category:** Rails\
**Created:** [November 12, 2009, 10:39pm UTC](https://www.ruby-forum.com/t/rjs-select-replace-html/178880 "2009-11-12T22:39:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![willclarkdesigns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@willclarkdesigns](https://www.ruby-forum.com/u/willclarkdesigns)\
**Post date:** [November 12, 2009, 10:39pm UTC](https://www.ruby-forum.com/t/rjs-select-replace-html/178880/1 "2009-11-12T22:39:15Z")

</div>

I need to update a series of html tags with the same content.

I’ve tried running the following in my rjs file:

page.select(".some\_class").each do |item|  
item.replace\_html(“Some Content”)  
end

But it won’t work.

However, when I run:

page.select(".some\_class").each do |item|  
item.hide  
end

it does.

I know part of the problem is that replace\_html needs the element id.  
But how, in RJS, would I do that?

Thanks  
Will

---

<div class="post-metadata">

**Author:** ![willclarkdesigns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@willclarkdesigns](https://www.ruby-forum.com/u/willclarkdesigns)\
**Post date:** [November 12, 2009, 11:21pm UTC](https://www.ruby-forum.com/t/rjs-select-replace-html/178880/2 "2009-11-12T23:21:03Z")

</div>

On Nov 12, 9:39 pm, Will C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> However, when I run:
> 
> page.select(“.some\_class”).each do |item|  
> item.hide  
> end
> 
> it does.
> 
> I know part of the problem is that replace\_html needs the element id.  
> But how, in RJS, would I do that?

something like page.replace\_html item, ‘some\_content’ might work  
(insude the each block)  
However when you get to the point that you’re fighting rjs you might  
as well just write the raw javascript

Fred

---

<div class="post-metadata">

**Author:** ![willclarkdesigns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@willclarkdesigns](https://www.ruby-forum.com/u/willclarkdesigns)\
**Post date:** [November 12, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/rjs-select-replace-html/178880/3 "2009-11-12T23:41:11Z")

</div>

Fred, that worked, I was just about to write my own method to handle it  
too.

Thanks!

- Will
