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

  • Home
  • SEARCH
  • 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 6215165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:00:23+00:00 2026-05-24T07:00:23+00:00

The question title is a bit obscure so let me explain. A requirement that

  • 0

The question title is a bit obscure so let me explain.

A requirement that was only explained to me recently is the use of jQuery in my project. But it has been noted that my functions are fine as is and can be reused as long as they contain some jQuery.

So I’m exploring the world of event listeners for the first time (js side not in the HTML)

A standard Jquery onclick event:

referenceToElement.onclick = function () { alert('here'); };

One thing I notice is that the function doesn’t actually have a name. Is there any clean way of doing something like:

referenceToElement.onclick = myOldJavascriptFunction();

function myOldJavascriptFunction()
{
    //blahblahblah
}

Is this good practice or is there a better way to do it. Will this even work now that I think of it?

  • 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-24T07:00:23+00:00Added an answer on May 24, 2026 at 7:00 am

    Even if the question is actually worth a downvote, since you could easily answer all those questions by searching, I’ll give you a headsup.

    That

    referenceToElement.onclick = function () { alert('here'); };
    

    is for sure no jQuery standard thing. It’s pure Javascript, adding a property to a DOM reference, in this case an anonymous function. However, you basically asked two questions now.

    • can we give that anonymous function a name ? => YES
    • can we reference a function which is defined somewhere else ? => YES

    To give it a name, we can just create a named function expression like this

    referenceToElement.onclick = function myFunctionName() { alert('here'); };
    

    To reference a function, we just pass in it’s name

    referenceToElement.onclick = myOldJavascriptFunction;
    

    Finally, jQuery’s syntax to add the same event listener would look like this:

    $( referenceToElement ).click( myOldJavascriptFunction );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the title is bit confusing for my question. Let me explain:- There
I know the title is bit confusing for my question. Let me explain:- There
I know the question title isn't the best. Let me explain. I do a
I know the title of the question is a bit odd. But I don't
OK, the question title is a bit crappy, but I didn't really know how
I'm a bit confuse how to name my question title. Let say my MySQL
I'm not really sure how to title this question but basically I have an
The question title is a bit strange because I'm not exactly sure how to
I'm a bit confused about mvc terminology. Using the question title as an example,
This question may seem a little bit stackoverflow-implementation specific, but I have seen a

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.