0

I apologize in advance for my ignorance. I'm teaching myself JavaScript and currently experimenting with events, though I still getting confused with JS objects, I am not to sure what the console prints on the following event.

element.onclick = function(objEvent) {
 Console.log(objEvent);
}

The console shows click clientX=76, clientY=20. What exactly is that information ? Are those properties of the event object ?

3
  • 1
    A really great resource that you should become familiar with is the Mozilla developer network. It has tons of information on js and the dom. This page discusses the event.clientX developer.mozilla.org/en-US/docs/Web/API/event.clientX Commented Mar 14, 2014 at 18:21
  • Yes, it is the properties of the event Commented Mar 14, 2014 at 18:22
  • 1
    Thanks for all answers. I've read about events and objects; however it is hard for me to understand how the event object is created and therefore what is exactly passed to the event handler. Apologize if the question was not well formulated, but your answer will definitely help me to understand the concept. Commented Mar 14, 2014 at 18:30

5 Answers 5

5

Are those properties of the event object ?

Yes, they are. In your case (for a click event) it's actually an object that's a superset of Event: MouseEvent.

Sign up to request clarification or add additional context in comments.

Comments

3

Whenever an event related to the DOM is fired, all of the relevant information about the action made is then gathered and stored on an object called event, which is, in your case, called objEvent.

An event caused by a keyboard action generates information about the keys that were pressed. An event caused by the mouse, on the other hand, generates information about the mouse's position, which is your case here (the X and Y position of the mouse cursor).

Comments

2

That's right.

From this event object there are various properties and methods. The properties you are seeing there are the mouse positions.

A common use of this event object might be to get the target / srcElement of the event

event.target | event.srcElement

eg - get the id of the target/srcElement

event.target.id

Very good object to study

Comments

1

Those are just the pixel coordinates on the screen of the place where your mouse clicked down.

clientX is the x coordinate

clientY is the y coordinate

Comments

0

Click is the event, clientX and clientY are the pixel coordinate location where the click happened. Checkout this for more info - http://www.javascripter.net/faq/mouseclickeventcoordinates.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.