Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
sonal

Referencing The Event

Recommended Posts

I'm having hard time to understand the topic, "referencing the event" on page no. 290. I'm reading it now for 4th time and experimenting with the code given.

 

I understand that the "target" point to the HTML element that triggered the event. So, we have used target.nodeName property to get it's reference.

 

If the target is a button, and I want to know the name of the button. I thought I can use the "name" property here like this:

 

var btName = target.nodeName.name //but this gives, "undefined"..

 

Why can't I use it like that?

Share this post


Link to post
Share on other sites

I think I'm moving in the circle.

I got the name of the element by, var btName = target.name;

 

"The nodeName property returns the name of the specified node." This sentence cause the confusion, but there is much more to this.

"If the node is an element node, the nodeName property will return the tagname." If I know the tagname, I can get the name of the element. If I know the element name, I can reference it directly. oh......everything gets confusing..

Share this post


Link to post
Share on other sites

sonal, I agree that there is some overlap in JS, which is probably what is creating this circular logic you seem to be stuck in.

I wouldn't worry about that too much though.

 

I think the important thing to understand is that directly referencing the event allows you to do things that can't be done any other way. For example, you can access pressed keys. the coordinates of the mouse on the screen, etc.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...