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 8801659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:53:28+00:00 2026-06-14T00:53:28+00:00

In jQuery you can have multiple calls for the various page and other events,

  • 0

In jQuery you can have multiple calls for the various page and other events, like so:

$(document).ready(function() {

And you can add multiple ‘ready’ function definitions along the way, you’re not limited to only one. Of course this helps by keeping code defined close to where it’s being used.

My question is, if in one of the document.ready function declarations I declare a local variable using var, will it be available in another document.ready function declaration that’s also used by the page?

I’m not sure how jQuery works in circumstances like these; whether it weaves the various functions’ scopes together somehow or if each of those functions runs in standalone fashion when the ready event is fired, each having no idea about the others’ variables. (I’d guess the second.)

  • 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-06-14T00:53:29+00:00Added an answer on June 14, 2026 at 12:53 am

    My question is, if in one of the document.ready function declarations I declare a local variable using var, will it be available in another document.ready function declaration that’s also used by the page?

    No, they’re local variables to the function you’re passing into document.ready.

    I’m not sure how jQuery works in circumstances like these; whether it weaves the various functions’ scopes together somehow or if each of those functions runs in standalone fashion when the ready event is fired, each having no idea about the others’ variables. (I’d guess the second.)

    And you’d be right. 🙂 In fact, jQuery can’t comingle the execution contexts of the functions, those are managed by the JavaScript engine.

    You can make them all share a parent execution context, though, by putting them all in a container function:

    (function() {
        // Shared by all functions within this block
        var foo = 42;
    
        // ...
    
        $(document).ready(function() {
            if (foo === 42) {
                // ...
                --foo;
            }
        });
    
        // ...
    
        $(document).ready(function() {
            if (foo > 0) {
                // ...
                --foo;
            }
        });
    
    })();
    

    I don’t think I’d advocate having multiple ready handlers (or even one, really) unless you’re writing a library. But that’s a different topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can you have multiple $(document).ready(function() sections? Is it OK to have multiple
In Jquery theres a function $(document).ready(function (){..} Is there such a thing in Sencha
I've attached multiple functions in multiple files to $(document).ready and would like to attach
I have a Jquery Mobile collapsible set , which can have any number of
Can I have text in the background of a jQuery UI progress bar? You
I have created a drop down with jQuery that can be seen here by
I have been trying to create a menu panel with jQuery that can be
I'm new to JQuery and was wondering how can I have Changes saved! displayed
I'm kind of new to JQuery and was wondering how can I have the
I have created a jQuery animation that can be seen by clicking the Preview

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.