# Rjs template ? (how to check for existence of a dom element?

**URL:** <https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411>\
**Category:** Rails\
**Created:** [March 27, 2006, 5:04am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411 "2006-03-27T05:04:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 5:04am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/1 "2006-03-27T05:04:06Z")

</div>

In my rjs template I’m using the following line.

page.visual\_effect :slideUp, ‘comment\_error\_details’, :duration =\> 0.5

It works fine if I have created the div with the  
id=“comment\_error\_details”,  
but if I haven’t created the error yet then my whole rjs template fails.

How can I check to see if an element has been created? I could then put  
the above line in an if statement.

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 5:09am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/2 "2006-03-27T05:09:33Z")

</div>

I guess the more broad question would be: Where can I find  
documentation on the available methods in rjs templates?

charlie bowman wrote:

> In my rjs template I’m using the following line.
> 
> page.visual\_effect :slideUp, ‘comment\_error\_details’, :duration =\> 0.5
> 
> It works fine if I have created the div with the  
> id=“comment\_error\_details”,  
> but if I haven’t created the error yet then my whole rjs template fails.
> 
> How can I check to see if an element has been created? I could then put  
> the above line in an if statement.

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 5:20am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/3 "2006-03-27T05:20:01Z")

</div>

Hi Charlie,

I am not quite sure if I’ve got your question right. But I would  
suggest  
just hidding the comment\_error\_details div and just call page.show  
before  
before applying the effect…

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 5:40am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/4 "2006-03-27T05:40:49Z")

</div>

It turns out that my problem is a little different than I thought. I  
decided to create the comment\_error div even if there were no errors. I  
thought this would solve my problem because the div would always be  
there. It turns out that you can’t call the visual effect “slideUp” if  
the div is empty. You can call fade on an empty div but you can’t call  
slideUp. Is there a way I can check the contents of a div in rjs  
templates? I really want to call the slideUp method, but I can only  
call it if the div isn’t empty

De Railed wrote:

> Hi Charlie,
> 
> I am not quite sure if I’ve got your question right. But I would  
> suggest  
> just hidding the comment\_error\_details div and just call page.show  
> before  
> before applying the effect…

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 5:37am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/5 "2006-03-27T05:37:35Z")

</div>

On Mar 26, 2006, at 9:04 PM, charlie bowman wrote:

> In my rjs template I’m using the following line.
> 
> page.visual\_effect :slideUp, ‘comment\_error\_details’, :duration  
> =\> 0.5
> 
> It works fine if I have created the div with the  
> id=“comment\_error\_details”,  
> but if I haven’t created the error yet then my whole rjs template  
> fails.

page \<\< “if($(‘my\_div’)) {”  
page.replace\_html my\_div, :partial =\> ?foo?  
page \<\< “}”

from \<[http://rails.techno-weenie.net/question/2006/3/24/](http://rails.techno-weenie.net/question/2006/3/24/)  
rjs\_templates\_checking\_if\_element\_exists\>

–  
Jason P.  
removed\_email\_address@domain.invalid

“The key to performance is elegance, not  
battalions of special cases.”

- Jon Bentley and Doug McIlroy

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 5:47am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/6 "2006-03-27T05:47:57Z")

</div>

On Mar 26, 2006, at 9:09 PM, charlie bowman wrote:

> I guess the more broad question would be: Where can I find  
> documentation on the available methods in rjs templates?

Documentation for RJS is still hard to come by. http://rails.techno-  
[weenie.net](http://weenie.net) has some good stuff as well as:

[http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates](http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates)  
\<[http://www.codyfauser.com/articles/2006/03/16/rjs-element-and-](http://www.codyfauser.com/articles/2006/03/16/rjs-element-and-)  
collection-proxies\>

As well as the Edge Rails Documentation itself:

\<[http://edgedocs.planetargon.org/classes/ActionView/Helpers/](http://edgedocs.planetargon.org/classes/ActionView/Helpers/)  
ScriptaculousHelper.html\>  
\<[http://edgedocs.planetargon.org/classes/ActionView/Helpers/](http://edgedocs.planetargon.org/classes/ActionView/Helpers/)  
PrototypeHelper/JavaScriptGenerator.html\>  
\<[http://edgedocs.planetargon.org/classes/ActionView/Helpers/](http://edgedocs.planetargon.org/classes/ActionView/Helpers/)  
PrototypeHelper.html\>  
\<[http://edgedocs.planetargon.org/classes/ActionView/Helpers/](http://edgedocs.planetargon.org/classes/ActionView/Helpers/)  
PrototypeHelper.html\>

–  
Jason P.  
removed\_email\_address@domain.invalid

“The key to performance is elegance, not  
battalions of special cases.”

- Jon Bentley and Doug McIlroy

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 6:10am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/7 "2006-03-27T06:10:58Z")

</div>

I’ve checked those sites, but it seems that there just isn’t any info  
out there yet.

Jason P. wrote:

> On Mar 26, 2006, at 9:09 PM, charlie bowman wrote:
> 
> > I guess the more broad question would be: Where can I find  
> > documentation on the available methods in rjs templates?
> 
> Documentation for RJS is still hard to come by. http://rails.techno-  
> [weenie.net](http://weenie.net) has some good stuff as well as:
> 
> [http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates](http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates)  
> \<[http://www.codyfauser.com/articles/2006/03/16/rjs-element-and-](http://www.codyfauser.com/articles/2006/03/16/rjs-element-and-)  
> collection-proxies\>

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 27, 2006, 6:51am UTC](https://www.ruby-forum.com/t/rjs-template-how-to-check-for-existence-of-a-dom-element/87411/8 "2006-03-27T06:51:05Z")

</div>

> I’ve checked those sites, but it seems that there just isn’t any info  
> out there yet.

cd to your rails directory (the framework, not your app), delete doc/  
and run ‘rdoc’ - a few minutes later you will have docs. pretty much  
everything is documented. you can peruse the ruby and resultant HTML  
sources to get a better understanding…
