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
-
Laurent Fortin September 4th, 2008 @ 06:53 AM
- → Tag changed from events to documentation events
I just noticed that this request was already done in ticket #158. I just mention it in case you want to process duplicate tickets.
-
John-David Dalton September 4th, 2008 @ 08:19 AM
- → State changed from new to duplicate
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
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.
