#323 ✓duplicate
Laurent Fortin

Doc improvement suggestion: Event.observe and Element#observe

Reported by Laurent Fortin | September 4th, 2008 @ 06:15 AM

In the API docs on http://www.prototypejs.org, there are good explanations about the Event.element(e) method, but not much about the 'this' reference that refers to the element on which the event handler was originally set. This can be confusing for the beginner.

For Element#observe, here is the current code example:


$(element).observe('click', function(event){
  alert(Event.element(event).innerHTML);
 });
// -> HTMLElement (and will display an alert dialog containing
// element's innerHTML when element is clicked).

I don't know if this would be fine, but I suggest a new example as something like this to explain the purpose of 'this':


$(element).observe('click', function(event){
  // this -> a reference to the element on which the 'click' event handler was originally set
  // Event.element(event) -> gets the element where the event occured

  alert(Event.element(event).innerHTML);
 });
// -> HTMLElement (and will display an alert dialog containing
// element's innerHTML when element is clicked).

Or maybe a small explanation about event bubbling could be nice.

It's all up to you guys, this was just my suggestion.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages