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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:08:49+00:00 2026-05-17T03:08:49+00:00

Sorry for asking, but how do I access myFunction() from someFunction ()? <script> $(document).ready(function()

  • 0

Sorry for asking, but how do I access myFunction() from someFunction()?

<script>
$(document).ready(function() {
    // Get messages
    var myFunction = function() {
      // doSth.
    }

    // Make the initial call on page load.
    myFunction();
);

function someFunction() {
    // Call the function a second time 
    myFunction();  // Call fails!
}
</script>
  • 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-17T03:08:49+00:00Added an answer on May 17, 2026 at 3:08 am

    Its more then a scope issue. Yes, you are scoping it to the anonymous function but even if you make it global by removing the var like this:

    $(document).ready(function() {
         // gets defined AFTER THE DOM IS READY
         myFunction = function() {
          // doSth.
         }
    }
    
    // is called BEFORE THE DOM IS READY
    myFunction();
    

    It STILL won’t work, because myFunction hasn’t been defined by the time you call someFunction. someFunction is running immediately before the document is ready, which is BEFORE myFunction is defined.

    Both functions need to be either in the document ready block, or outside it. If you need to manipulate DOM elements, I’d recommend inside.

    If someFunction is called for a handler, you can remove the var declaration from myFunction and it will work as expected, because this will put myFunction in the global scope.

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

Sidebar

Related Questions

sorry for asking this question again but i didnt get much help on the
Sorry for asking this but, I cant found a solution that will get this
Sorry for asking this again but ppl seem to connect csrf only with form
Sorry for asking a totally basic question, but if I have a synthesized property
yes its a joomla question and im sorry to annoy but asking on the
Sorry for the title but I don't know other way of asking. EDITED FOR
Okay, I just can't get my head around multi-threading scenarios properly. Sorry for asking
Sorry asking so many questions but believe me.. I tried Google first. :) When
Sorry for asking a basic question like this but I've been reading on this
Sorry for asking this question, but I searched all Java-related questions, but I got

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.