- 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
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Prototype - Element Object
The Element object provides various utility functions for manipulating elements in the DOM.
Here is the list of all the utility functions with examples. All the methods defined here are automatically added to any element accessed using the $() function.
So, writing Element.show('firstDiv'); is the same as writing $('firstDiv').show();
Prototype Element Method
NOTE − Make sure you have at least version 1.6 of prototype.js.
|S.No.||Method & Description|
Turns element into an absolutely-positioned element without changing its position in the page layout.
Adds the given CSS class name to the element's class names.
Makes it possible to mix in your own methods to the Element object, which you can later use as methods of extended elements.
Finds all siblings of the current element that match the given selector(s).
Collects all of element's ancestors and returns them as an array of extended elements.
Collects all of the element's children and returns them as an array of extended elements.
Deprecated. Returns a new instance of ClassNames, an Enumerable object used to read and write CSS class names of element.
Removes all of element's text nodes, which contain only whitespace. Returns element.
Clones the position and/or dimensions of source onto element as defined by the optional argument options.
Returns the offsets of element from the top left corner of the document.
Calculates the cumulative scroll offset of an element in nested scrolling containers.
Checks if the element is a descendant of ancestor.
Collects all of element's descendants and returns them as an array of extended elements.
Returns element's first descendant that matches cssRule. If no cssRule is provided, all descendants are considered. If no descendant matches these criteria, undefined is returned.
Tests whether element is empty (i.e., contains only whitespace).
Extends element with all of the methods contained in Element.Methods and Element.Methods.Simulated.
Fires a custom event with the current element as its target.
Returns the first child that is an element. This is opposed to firstChild DOM property, which will return any node.
Finds the computed width and height of an element and returns them as key/value pairs of an object.
Deprecated. Fetches all of element's descendants, which have a CSS class of className and returns them as an array of extended elements. Please use $$().
Deprecated. Takes an arbitrary number of CSS selectors (strings) and returns an array of extended children of element that match any of them. Please use $$().
Finds and returns the computed height of element.
Returns element's closest positioned ancestor. If none is found, the body element is returned.
Returns the given CSS property value of element. Property can be specified in either of its CSS or camelized form.
Finds and returns the computed width of element.
Checks whether element has the given CSS className.
Hides and returns element.
Returns element's id attribute if it exists, or sets and returns a unique, auto-generated id.
Deprecated. Collects all of the element's immediate descendants (i.e., children) and returns them as an array of extended elements. Please use childElements().
Inserts content before, after, at the top of, or at the bottom of element.
Returns the debug-oriented string representation of element.
Simulates the poorly supported CSS clip property by setting element's overflow value to 'hidden'. Returns element.
Allows for the easy creation of CSS containing block by setting element's CSS position to 'relative' if its initial position is either 'static' or undefined. Returns element.
Checks if element matches the given CSS selector.
Returns element's following sibling that matches the given cssRule.
Collects all of element's next siblings and returns them as an array of extended elements.
Registers an event handler on element and returns element.
Returns element's offset relative to its closest positioned ancestor.
Returns element's previous sibling that matches the given cssRule.
Collects all of element's previous siblings and returns them as an array of extended elements.
Returns the value of element's attribute or null if attribute has not been specified.
Recursively collects elements whose relationship is specified by property.
Turns element into an relatively-positioned element without changing its position in the page layout.
Completely removes element from the document and returns it.
Removes element's CSS className and returns element.
Replaces element by the content of the html argument and returns the removed element.
Scrolls the window so that element appears at the top of the viewport. Returns element.
Takes an arbitrary number of CSS selectors (strings) and returns an array of extended descendants of element that match any of them.
Sets the visual opacity of an element while working around inconsistencies in various browsers.
Modifies element's CSS style properties.
Displays and returns element.
Collects all of element's siblings and returns them as an array of extended elements.
Unregisters handler and returns element.
Toggles the visibility of element.
Toggles element's CSS className and returns element.
Sets element's CSS overflow property back to the value it had before Element.makeClipping() was applied. Returns element.
Sets element back to the state it was before Element.makePositioned was applied to it. Returns element.
Returns element's first ancestor that matches the given cssRule.
Replaces the content of element with the provided newContent argument and returns element.
Returns the X/Y coordinates of element relative to the viewport.
Returns a Boolean indicating whether or not element is visible.
Wraps an element inside another, then returns the wrapper.
Adds, specifies or removes attributes passed as either a hash or a name/value pair.