# Dom:loaded in application.js and view

**URL:** <https://www.ruby-forum.com/t/dom-loaded-in-application-js-and-view/187772>\
**Category:** Rails\
**Created:** [April 29, 2010, 3:14am UTC](https://www.ruby-forum.com/t/dom-loaded-in-application-js-and-view/187772 "2010-04-29T03:14:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [April 29, 2010, 3:14am UTC](https://www.ruby-forum.com/t/dom-loaded-in-application-js-and-view/187772/1 "2010-04-29T03:14:55Z")

</div>

I register ajax listeners in my application.js in the dom:loaded  
function. In some of my views I also need to use the dom:loaded event  
to do other javascript stuff. Since I already have my dom:loaded in  
application.js, can I specify another dom:loaded in the script tag in  
my view or is there a better way to do it?

I know this could be a prototype question, but since this is rails, I  
thought someone might have tried this already.

Thanks

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [April 29, 2010, 10:15pm UTC](https://www.ruby-forum.com/t/dom-loaded-in-application-js-and-view/187772/2 "2010-04-29T22:15:06Z")

</div>

badnaam wrote:

> I register ajax listeners in my application.js in the dom:loaded  
> function. In some of my views I also need to use the dom:loaded event  
> to do other javascript stuff. Since I already have my dom:loaded in  
> application.js, can I specify another dom:loaded in the script tag in  
> my view or is there a better way to do it?
> 
> I know this could be a prototype question, but since this is rails, I  
> thought someone might have tried this already.

> **[Layouts and Rendering in Rails — Ruby on Rails Guides](https://guides.rubyonrails.org/layouts_and_rendering.html#using-content-for)**
>
> Layouts and Rendering in RailsThis guide covers the basic layout features of Action Controller and Action View.After reading this guide, you will know: How to use the various rendering methods built into Rails. How to create layouts with multiple...

## Specifically this part:

## The content\_for method is very helpful when your layout contains distinct regions such as sidebars and footers that should get their own blocks of content inserted. Itâ€™s also useful for inserting tags that load page-specific javascript or css files into the header of an otherwise generic layout.
