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

The Archive Base Latest Questions

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

How come when I use the following code, clicking on Click Here doesn’t trigger

  • 0

How come when I use the following code, clicking on “Click Here” doesn’t trigger an alert? Why can’t I call methods of things other than the window object? E.g. a method of the test1 function?

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

function test1() {
    test1.test2 = function() {
        alert('Test');
    }
}

</script>
</head>
<body>
<div onClick="test1.test2()">Click Here</div>
</body>
</html>
  • 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-20T07:46:24+00:00Added an answer on May 20, 2026 at 7:46 am

    Since you’re defining test1.test2 inside of test1, it won’t actually be defined until test1 executes.

    Adding a call to test1() immediately after its definition in the script block would make your code work.

    You could also move the definition of test1.test2 outside of test1, though if anything in test2 relies on variables which are scoped to test1 you’d have an issue.

    All that said, you’re describing a weird scenario, code-wise.

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

Sidebar

Related Questions

I come from a C++ background where I can use template mixins to write
I use the following code to get a screenshot of the screen and save
In the following code, I want a tool-tip to come up when the user
I am using following code to limit use of resources. Once in a while(after
I'm trying to use MonadError together with Parsec. I've come up with the following
I come from a mainly PHP background and make good use of the Apache
I use a lot of lists and arrays but I have yet to come
I am trying to come up with the best data structure for use in
I'm planning to use MS entity framework for new web apps (come on EF
Sam Ruby, author of RESTful Web Services seems to come out against the use

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.