# Can you apply effects to elements create in same RJS file?

**URL:** <https://www.ruby-forum.com/t/can-you-apply-effects-to-elements-create-in-same-rjs-file/59902>\
**Category:** Rails\
**Created:** [May 8, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/can-you-apply-effects-to-elements-create-in-same-rjs-file/59902 "2006-05-08T12:08:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nigelthorne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c2a13f/32.png) [@nigelthorne](https://www.ruby-forum.com/u/nigelthorne)\
**Post date:** [May 8, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/can-you-apply-effects-to-elements-create-in-same-rjs-file/59902/1 "2006-05-08T12:08:06Z")

</div>

I am trying to create a new element in a list and highlight it.  
I am doing the following in my rjs file:

page.insert\_html :after, ‘bananalist\_header’, :partial =\> ‘banana’  
page.visual\_effect :highlight, “banana#{banana.id}”, :duration =\> 1

The first line creates a new element with the id= ‘banana3’ say…  
The second line then tries to highlight the new element.

This script fails as the second element doesn’t exist before the script  
starts running. Is there some way to make this work? If I change the  
second line to reference an existing element ‘banana1’ say, then it  
highlights it fine.

Any suggestions?

Cheers  
Nigel

---

<div class="post-metadata">

**Author:** ![nigelthorne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c2a13f/32.png) [@nigelthorne](https://www.ruby-forum.com/u/nigelthorne)\
**Post date:** [May 8, 2006, 12:34pm UTC](https://www.ruby-forum.com/t/can-you-apply-effects-to-elements-create-in-same-rjs-file/59902/2 "2006-05-08T12:34:03Z")

</div>

It works for me, I do that quite often. You’re probably not  
highlighting the right id, or maybe you’ve got the same id in your  
document twice.

-Jonathan.

---

<div class="post-metadata">

**Author:** ![nigelthorne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c2a13f/32.png) [@nigelthorne](https://www.ruby-forum.com/u/nigelthorne)\
**Post date:** [May 8, 2006, 12:39pm UTC](https://www.ruby-forum.com/t/can-you-apply-effects-to-elements-create-in-same-rjs-file/59902/3 "2006-05-08T12:39:49Z")

</div>

Nigel T. wrote:

> I am trying to create a new element in a list and highlight it.  
> I am doing the following in my rjs file:
> 
> page.insert\_html :after, ‘bananalist\_header’, :partial =\> ‘banana’  
> page.visual\_effect :highlight, “banana#{banana.id}”, :duration =\> 1

Could it be that it’s supposed to be #{@banana.id} ? (I don’t know,  
just guessing).

Alan

---

<div class="post-metadata">

**Author:** ![nigelthorne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c2a13f/32.png) [@nigelthorne](https://www.ruby-forum.com/u/nigelthorne)\
**Post date:** [May 8, 2006, 5:53pm UTC](https://www.ruby-forum.com/t/can-you-apply-effects-to-elements-create-in-same-rjs-file/59902/4 "2006-05-08T17:53:30Z")

</div>

On Monday, May 08, 2006, at 12:08 PM, Nigel T. wrote:

> starts running. Is there some way to make this work? If I change the  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

All the lines in the RJS file fire simultaneously.

If you wrap the second line in a delay(0.1), it should work fine and  
really not be noticable.

\_Kevin
