Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1038497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:58:58+00:00 2026-05-16T14:58:58+00:00

I am using a web application framework (Symfony 1.3.6), which follows the MVC pattern.

  • 0

I am using a web application framework (Symfony 1.3.6), which follows the MVC pattern.

The view layer is comprised of a template decorator. The template file may also include other templates – this is what gives rise to my question.

Assuming that there is a page (lets call it the ‘homepage’), which is comprised of several templates – (the code has been refactored out so the ‘sub templates’ can be used on other pages.

As a result of the refactoring, the small templates – which are used by the main template – (‘homepage’ in our example), need to contain their jQuery related code.

lets say the homepage template uses 2 ‘sub templates:

  • template A
  • template B

assume that template A consists of the following snippet:

<div id="field1">This is field 1</div>
<script type="text/javascript">
$(document).ready(function(){
   $('#field1').click(function(){
      alert('Field 1 clicked!');
   });
</div>
</script>

assume that template B consists of the following snippet:

<div id="field2">This is field 2</div>
<script type="text/javascript">
$(document).ready(function(){
   $('#field2').click(function(){
      alert('Field 2 clicked!');
   });
</div>
</script>

Now the template ‘homepage’ looks like this:

<html>
  <head>
    <title>Multiple jQuery snippet test</title>
    <script src="path_to_jquery"></script>
 </head>
 <body>
   <div>include_template('template A')</div>
   <div>include_template('template B')</div>
 </body>
</html>

I have tried this – and to my suprise, it worked in that there was only one $(document).ready() in the merged, final page (‘homepage).

I am not sure if either my Browser (Firefox) or the web framework (Symfony), had done some ‘cleaning up’ behind the scenes.

So my question is that what is the best way to proceed if you want to refactor jQuery functionality into ‘little reusable templates’ that can be reused to provide the same functionality in different pages?

BTW, I hope no one suggests writing a jQuery plugin, as that is SO not what I’m talking about.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:58:58+00:00Added an answer on May 16, 2026 at 2:58 pm

    There are no problems with multiple $(document).ready() calls, only a couple of caveats:

    • Reduced readability.
    • Scope: a function/variable/object declared inside one $(document).ready() will not be visible in any others. See this simple demo.

    Also see this previous question on SO:

    • Can you have multiple $(document).ready(function(){ … }); sections?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I am afraid the gain has nothing to do with… May 17, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer The problem is that the shell expands variable names inside… May 17, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer How about going into this direction? SELECT values.value, values.datetime FROM… May 17, 2026 at 12:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

In my PHP application ( constructed using symfony framework and Propel ORM), when I
When using the JSF Web application framework, ID of the elements inside a form
I am creating a web application framework, in which I am providing support for
I'm using Java+struts2+JSP as the web application framework. I have to pass some huge
I got a web application using the spring-security framework. I setted up a database
I'm working on a web application written in Java using the Tapestry 5.1.0.5 framework.
Ok, so here's the issue. Currently I'm using the symfony framework to develop a
I'm developing a new experimental web-application framework, and I decided to give RESTful some
The web-application is a custom-built CMS which has several sub-applications and each one of
I have an application solution which is made up of a web app written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.