# Re: How to check the existence of div?

**URL:** <https://www.ruby-forum.com/t/re-how-to-check-the-existence-of-div/138124>\
**Category:** Rails\
**Created:** [May 20, 2008, 1:02pm UTC](https://www.ruby-forum.com/t/re-how-to-check-the-existence-of-div/138124 "2008-05-20T13:02:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@fcheung](https://www.ruby-forum.com/u/fcheung)\
**Post date:** [May 20, 2008, 1:02pm UTC](https://www.ruby-forum.com/t/re-how-to-check-the-existence-of-div/138124/1 "2008-05-20T13:02:35Z")

</div>

On 20 May 2008, at 11:53, Nathan E. wrote:

> then?  
> Two ways…simple way is simply write the function in pure javascript  
> and then invoke it in the rjs…i.e page.call “someFunction”,  
> “param1”,  
> “param2”
> 
> but what if I REALLY want to be able to dynamically evaluate ruby code  
> as part of the template…I have used a plugin called MinusMOR
> 
> [http://agilewebdevelopment.com/plugins/minusmor](http://agilewebdevelopment.com/plugins/minusmor)

Neat. Not surprising to see yet another excellent thing from Dan  
Webb!. With the latest stuff I’ve been I doing I’ve taking to just the  
writing the javascript statically.  
Actions render :json (or just html fragments) and the ajax callbacks  
on the other side put things together. With a good dose of prototype  
javascript isn’t that bad. And I can write better unit tests for my  
static javascript than I can for generated javacscript.

Fred

–  
My ramblings: [http://www.spacevatican.org](http://www.spacevatican.org)

---

<div class="post-metadata">

**Author:** ![fcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@fcheung](https://www.ruby-forum.com/u/fcheung)\
**Post date:** [May 20, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/re-how-to-check-the-existence-of-div/138124/2 "2008-05-20T14:37:34Z")

</div>

page.select(“##{params[:id]}parents”).any(elem){|elem|.replace\_html  
‘blah’}

page.select will return a collection of dom elements that match a css  
selector, so the first part of that line is selecting the element with  
id=‘xparents’

The second half of the line (\*.any(){}) translates to a javascript  
iterator on the returned collection. I have not tested that  
particular code but I’ve used rjs like it to conditionally update the  
browser in the past.

On May 20, 7:01 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
