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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:19:32+00:00 2026-05-28T04:19:32+00:00

I have this: function cool(){ function alsocool(){ } } And I run the cool()

  • 0

I have this:

function cool(){
   function alsocool(){

   }
}

And I run the cool() on button click:

$(selector).on('click', function(){
 cool();
}

How can I run the cool() and the alsocool() from the same click? Note that I don’t want to do:

function cool(){
   function alsocool(){

   }
   alsocool();
}

If I do :

$(selector).on('click', function(){
     cool(); alsocool();
    }

it doesn’t work.

Is it possible to run a function inside a function on the same call?

EDIT:

I DO WANT to pass cool() since obviously alsocool() is not recognized once its inside function cool() BUT cool(); is passed from many selector thus I want to know from which selector is passed and take the appropriate action.

Example I want something like this:

function cool(){

// If this was called by button1, run alsocool() else bypass it
       function alsocool(){

       }
// some code goes here

}

$("#button1").on('click', function(){
         cool(); alsocool();
         // If button1 clicked, run cool AND alsocool
        }
$("#button2").on('click', function(){
         cool(); // If button2 clicked, run cool ONLY.
    }
  • 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-28T04:19:32+00:00Added an answer on May 28, 2026 at 4:19 am

    The answer is simple: It is impossible.
    The inner function is local to the containing function’s scope so unless that function calls it, it cannot be called at all.

    If you want both functions to be reachable from outside, define alsocool outside cool, i.e. on the same level as cool.


    As per your comment, here’s a way that would use a parameter to determine if the inner function should be called or not:

    function cool(callInner){
        function alsocool(){
    
        }
        if(callInner) {
            alsocool();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function in my Javascript Code that updates html fields with their
I have this function from a plugin (from a previous post) // This method
I have this function to read in all ints from the file. The problem
I have this function on my controller (Im using CodeIgniter) that reads the database,
So I have this: <?php echo ' <script> $(function(){ $("a#yeah").click(function(){ $.ajax({ url: "ajax.php?action=yeah&id='.$id.'", success:
So I have this neat little javascript function that I'm using to print text
I saw a cool style/js function (I can tell what it is) that implemented
I have this cool little snippet that I found, which adds a shadow to
I have a function that gets users from a MySQL database, the results rows
I have this function in my head: <head> window.onload = function(){ var x =

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.