- Prototype Tutorial
- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
- Prototype Useful Resources
- Prototype - Quick Guide
- Prototype - Useful Resources
- Prototype - Discussion
Prototype - extend() Method
This method extends element with all of the methods contained in Element.Methods and Element.Methods.Simulated.
If element is an input, textarea or select tag, it will also be extended with the methods from Form.Element.Methods.
If it is a form tag, it will also be extended with Form.Methods.
Syntax
element.extend();
Return Value
None.
Example
By extending an element with Prototype's custom methods, we can achieve that syntactic sugar and ease of use we all crave for. For example, you can do the following with an extended element −
element.update('hello world');
And since most methods of Element return the element they are applied to, you can chain methods like so −
element.update('hello world').addClassName('greeting');
Note that all of the elements returned by Element methods are extended (yes even for methods like Element.siblings, which return arrays of elements) and Prototype's flagship utility methods $() and $$() obviously also return extended elements.
To Continue Learning Please Login
Login with Google