# Triggering Javascript after AJAX

**URL:** <https://www.ruby-forum.com/t/triggering-javascript-after-ajax/173050>\
**Category:** Rails\
**Created:** [August 1, 2009, 1:26am UTC](https://www.ruby-forum.com/t/triggering-javascript-after-ajax/173050 "2009-08-01T01:26:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 1, 2009, 1:26am UTC](https://www.ruby-forum.com/t/triggering-javascript-after-ajax/173050/1 "2009-08-01T01:26:48Z")

</div>

I have a page starting out with:

After an AJAX call, the innerhtml is updated to:

where after the new content is loaded, I want to run

$(‘newDiv’).fade({ duration: 2.0, from: 1, to: 0 });

I can’t figure out how to set this up. Code examples or links to  
documentation would be nice… 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 1, 2009, 1:43am UTC](https://www.ruby-forum.com/t/triggering-javascript-after-ajax/173050/2 "2009-08-01T01:43:47Z")

</div>

see this creencast:

> **[\#136 jQuery - RailsCasts](http://railscasts.com/episodes/136-jquery)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

there ryan Bates shows how to use javascript after an ajax call and  
more. maybe it could help you.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 1, 2009, 4:33am UTC](https://www.ruby-forum.com/t/triggering-javascript-after-ajax/173050/3 "2009-08-01T04:33:31Z")

</div>

I’m an idiot. A simple :onsuccess callback was all I needed.

But, on the upside, at the same time I figured out how insert  
javascript to be run after a “fake ajax file upload by redirect to  
iframe hack”.
