# Help with an RJS

**URL:** <https://www.ruby-forum.com/t/help-with-an-rjs/152187>\
**Category:** Rails\
**Created:** [October 30, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187 "2008-10-30T22:56:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 30, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/1 "2008-10-30T22:56:34Z")

</div>

Hello, I have a code on a RJS where I want to check if an element in  
the DOM has child elements, if not, show a message.

1.page["event\_"removed\_email\_address@domain.invalid\_s].visual\_effect :fade #This works  
2.page \<\< “if $(‘single\_blog\_info\_box\_480’).childElements().length ==  
0 {”  
3.page[“message”].visual\_effect :appear  
4.page \<\< “}”

Line 1 is working. It removes an event from the view. The problem is  
in line 2. I am calling childElements on a div called  
‘single\_blog\_info\_box\_480’ (which contains the events). The idea is to  
make a message appear when there are no more events left. The thing is  
that I currently have 3 events and everytime the RJS is executed it  
shows the same 3 events even though events have become hidden. Can  
somebody guide me on how to do this or what the problem is?

Thanks,

Elioncho

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 30, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/2 "2008-10-30T23:06:33Z")

</div>

On 30 Oct 2008, at 21:55, elioncho wrote:

> Line 1 is working. It removes an event from the view. The problem is  
> in line 2. I am calling childElements on a div called  
> ‘single\_blog\_info\_box\_480’ (which contains the events). The idea is to  
> make a message appear when there are no more events left. The thing is  
> that I currently have 3 events and everytime the RJS is executed it  
> shows the same 3 events even though events have become hidden. Can  
> somebody guide me on how to do this or what the problem is?

you need to have () surrounding the condition.

Fred

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 31, 2008, 1:03am UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/3 "2008-10-31T01:03:03Z")

</div>

why don’t you write 2–4 line into a single line ?

page \<\< “if ($(‘single\_blog\_info\_box\_480’).childElements().length ==  
0 ){$(‘message’).Appear;}”

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 30, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/4 "2008-10-30T23:41:06Z")

</div>

I added the () but that’s not the problem. I added the next alert and  
it shows the events length. But if I remove another event it still  
shows the same number.

page \<\< “alert($(‘single\_blog\_info\_box\_480’).childElements().length)”

On Oct 30, 5:05 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 31, 2008, 3:00am UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/5 "2008-10-31T03:00:39Z")

</div>

The childElements length never changes when I make the event  
disappear. It’s like it remains with what initially is loaded on the  
html eventhough I have hide this elements.

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 31, 2008, 3:45am UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/6 "2008-10-31T03:45:16Z")

</div>

elioncho wrote:

> The childElements length never changes when I make the event  
> disappear. It’s like it remains with what initially is loaded on the  
> html eventhough I have hide this elements.

I don’t use these effects a lot, but the fade effect in prototype/  
scriptaculous is probably setting the css ‘display’ property to none  
to take it out of the visual display of the document. It’s still  
sitting there in the dom, so ‘childElements’ is probably counting it;  
it’s just that it doesn’t appear in the visual flow.

–  
Daniel B.

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [October 31, 2008, 4:10am UTC](https://www.ruby-forum.com/t/help-with-an-rjs/152187/7 "2008-10-31T04:10:25Z")

</div>

Thanks all of you for help. Daniel I think that’s what’s happening.  
I’ll try another approach.

Elioncho
