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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:48:32+00:00 2026-06-11T14:48:32+00:00

Possible Duplicate: I trying to get the target element’s id when function fired, but

  • 0

Possible Duplicate:
I trying to get the target element’s id when function fired, but this keyword returns undefined

— HTML file —

<a href="#link_1" id="id_0" onclick = "getElement('parms1', 'parms2', 'parms3')">0</a>
<a href="#link_2" id="id_1" onclick = "getElement('parms1', 'parms2', 'parms3')">1</a>
<a href="#link_1" id="id_2" onclick = "getElement('parms1', 'parms2', 'parms3')">2</a>

— Js file —

function getElement = function(a, b, c){
    // trying to get the clicked element
    alert(this); // returns 'undefined'
}

Note: I can’t modify / add / remove parameters in onclick function, but I can add / remove parameters in js file

Problem: How to identify that which element was clicked without modifying the onclick function parameters?

  • 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-06-11T14:48:34+00:00Added an answer on June 11, 2026 at 2:48 pm

    Simple fix:

    Change the HTML to:

    <a href="#link_1" id="id_0" onclick = "getElement('parms1', 'parms2', 'parms3',this,event)">0</a>
    

    And the function definition to:

    //function getElement = function(){};doesn't really make sense...
    function getElement (a, b, c,clicked,e)
    {
        alert(clicked.id);//alerts id of clicked link
        alert((e.target || e.srcElement).id);//via the event object
    }
    

    So the choice is yours, either pass this and event to the function, or just event, or just this and you’re good to go.

    You might want to look into delegating this type of events, though

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

Sidebar

Related Questions

Possible Duplicate: How can I get an element's serialised HTML with PHP's DOMDocument? PHP
Possible Duplicate: Get class of generic I'm trying to do this: public static<T extends
Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
Possible Duplicate: jQuery get input value after keypress I'm trying to get an input
Possible Duplicate: Uploadify: show error message from HTTP response I am trying to get
Possible Duplicate: Change an element's CSS class with JavaScript I'm trying to set div's
Possible Duplicate: How do I get this CSS text-decoration issue to work? I'm using
Possible Duplicate: How to reference mockito within tycho? I am trying to get a
Possible Duplicate: A call to PInvoke function '[…]' has unbalanced the stack I'm trying
Possible Duplicate: Trying to get tag-it to work with an AJAX call How can

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.