# "onload" event handler inside a div

**URL:** <https://www.ruby-forum.com/t/onload-event-handler-inside-a-div/52973>\
**Category:** Rails\
**Created:** [January 22, 2006, 1:49am UTC](https://www.ruby-forum.com/t/onload-event-handler-inside-a-div/52973 "2006-01-22T01:49:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [January 22, 2006, 1:49am UTC](https://www.ruby-forum.com/t/onload-event-handler-inside-a-div/52973/1 "2006-01-22T01:49:34Z")

</div>

Hi. I need help on what is essentially putting an “onload” event handler  
into a div. I am using render :partial and when the partial is loaded, I  
would like the divs to show using an effect from a library such as  
scriptaculous or moofx. However, there is no “onload” for a div. I was  
wondering what alternative methods I should use to achieve this.

Thanks!

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [January 25, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/onload-event-handler-inside-a-div/52973/2 "2008-01-25T16:04:55Z")

</div>

Dave wrote:

> Hi. I need help on what is essentially putting an “onload” event handler  
> into a div. I am using render :partial and when the partial is loaded, I  
> would like the divs to show using an effect from a library such as  
> scriptaculous or moofx. However, there is no “onload” for a div. I was  
> wondering what alternative methods I should use to achieve this.
> 
> Thanks!

I’m wondering about this meself. Does anyone have ideas on this? I  
have the effect working if I do “onClick”, but how can I get the effect  
to work with “onLoad” for a div?

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [January 25, 2008, 6:29pm UTC](https://www.ruby-forum.com/t/onload-event-handler-inside-a-div/52973/3 "2008-01-25T18:29:27Z")

</div>

Dave wrote:

> Hi. I need help on what is essentially putting an “onload” event handler  
> into a div. I am using render :partial and when the partial is loaded, I  
> would like the divs to show using an effect from a library such as  
> scriptaculous or moofx. However, there is no “onload” for a div. I was  
> wondering what alternative methods I should use to achieve this.
> 
> Thanks!

If you put the j-script you want to execute in a block  
that appears immediately after the div, and have the script execute  
immediately, then it will only run immediately after the div is in  
place.

E.g.:

 content content content

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [January 26, 2008, 1:30am UTC](https://www.ruby-forum.com/t/onload-event-handler-inside-a-div/52973/4 "2008-01-26T01:30:28Z")

</div>

here’s an example: this is in an RJS file called create.rjs:

page.visual\_effect :blind\_up, “new\_comment\_form\_for\_post\_#{@post.id}”

this is called from the create action of a controller…in the create  
action would be something like this:

respond\_to do |format|  
format.js  
end

which would call the RJS…the RJS does the scriptaculous effect that  
makes the div roll up like a blind…the div id is in the speech marks  
after the :blind\_up command…

further reading: [http://script.aculo.us](http://script.aculo.us)
