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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:46:43+00:00 2026-05-26T09:46:43+00:00

My HTML: <div id=x onclick=clickHandler(event)> <div id=button1>This turns green</div> <div id=button2>This turns blue</div> </div>

  • 0

My HTML:

<div id="x" onclick="clickHandler(event)">
   <div id="button1">This turns green</div>
   <div id="button2">This turns blue</div>
</div>

So first of all, why am I supposed to be passing “event” into the click handler and is event some kind of system keyword?
Also, since the click handler is identified on the container div, how do I know which button has been clicked?

  • 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-26T09:46:43+00:00Added an answer on May 26, 2026 at 9:46 am

    event is an Event object which is created automatically when an event is fired. Note that you don’t have to call it event (I tend to call it simply e). That Event object has a number of properties which describe the event it represents. In this case, the one you’re interested in would be target, which shows the element that was the source of the event:

    function clickHandler(e) {
        var target = e.target;
    }
    

    Here’s a working example.

    Unfortunately, it’s never quite that simple. While the specification says it should be event.target, Internet Explorer likes to be different, and chooses to use event.srcElement, so you probably want to put in a check to make sure event.target exists! For example:

    function clickHandler(e) {
        var target = (e.target) ? e.target : e.srcElement;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First Case : <div> <a href=# onclick=doIt(this)>some job</a> <div> i can do: <script> function
In the main gadget html, there is a div with an onclick that calls
I made this Greasemonkey script: var maxpi = 250; var p1 = /html/body/div/div[2]/div/div[2]/table[2]/tbody/tr[1]/td[11]; var
$(this).parent().parent() .children(this.attr(tagName).toLowerCase()) .css(background-color, yellow); xpath: /html/body/div/table/tr/td/b/a $(this).tagName is Anchor <a> the problem with this
$('div.box').html(hello) puts the word hello inside all my div's of class 'box'. They all
I have the following html page: <div id=a onclick =javascript:click();>a</div> <div id=b onclick =javascript:click();>b</div>
Basically there are multiple options to catch onclick events with javascript. The html: <div
I have a code like this: <a href=somewhere.html> <img src=blabla> <div class=wrap> <div id=id1
HTML page: FIRST ELEMENT The onclick function of FIRST ELEMENT (which is < h1
i have a site with links that look like this: onClick = ajax('link.html','contentdiv') but

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.