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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:44:40+00:00 2026-05-21T19:44:40+00:00

I have an onclick attribute on my link: <a href=# onclick=myFunc(1,2,3)>click</a> That points to

  • 0

I have an onclick attribute on my link:

<a href="#" onclick="myFunc(1,2,3)">click</a>

That points to this event handler in JavaScript:

function myFunc(p1,p2,p3) {
    //need to refer to the current event object:
    alert(evt.type);        
}

Since the event object “evt” is not passed to a parameter, is it still possible to obtain this object?

I tried window.event and $(window.event), but both are undefined.

Any idea?

  • 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-21T19:44:41+00:00Added an answer on May 21, 2026 at 7:44 pm

    Since the event object “evt” is not passed from the parameter, is it still possible to obtain this object?

    No, not reliably. IE and some other browsers make it available as window.event (not $(window.event)), but that’s non-standard and not supported by all browsers (famously, Firefox does not).

    You’re better off passing the event object into the function:

    <a href="#" onclick="myFunc(event, 1,2,3)">click</a>
    

    That works even on non-IE browsers because they execute the code in a context that has an event variable (and works on IE because event resolves to window.event). I’ve tried it in IE6+, Firefox, Chrome, Safari, and Opera. Example: http://jsbin.com/iwifu4

    But your best bet is to use modern event handling:

    HTML:

    <a href="#">click</a>
    

    JavaScript using jQuery (since you’re using jQuery):

    $("selector_for_the_anchor").click(function(event) {
        // Call `myFunc`
        myFunc(1, 2, 3);
    
        // Use `event` here at the event handler level, for instance
        event.stopPropagation();
    });
    

    …or if you really want to pass event into myFunc:

    $("selector_for_the_anchor").click(function(event) {
        myFunc(event, 1, 2, 3);
    });
    

    The selector can be anything that identifies the anchor. You have a very rich set to choose from (nearly all of CSS3, plus some). You could add an id or class to the anchor, but again, you have other choices. If you can use where it is in the document rather than adding something artificial, great.

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

Sidebar

Related Questions

I usually have to bind a JavaScript function to an anchor-click event. That is
I have an internal website that has a link with NO onClick attribute present.
Usually, when people click on a link, I have onclick bound to it. And
I have a onclick event that is like: public void OnMyButton_Click(object sender, EventArgs e)
I have an onclick function that I want to add an anchor to the
I have a div which I have attached an onclick event to. in this
I have an onclick function which performs several tasks. In another JavaScript function I
I have some javascript click handlers that don't do what I want in IE8.
I have code <a href=javascript:someFunction(this); tabindex=0>Some text</a> Is it possible to pass element into
I have a link and on clicking it, a function is called. In that

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.