Jump to content
Larry Ullman's Book Forums

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?

Link to comment
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..

Link to comment
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.

Link to comment
Share on other sites

 Share

×
×
  • Create New...