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();
Method | Description |
absolutize() | Turns element into an absolutely-positioned element without changing its position in the page layout. |
addClassName() | Adds the given CSS class name to the element's class names. |
addMethods() | Makes it possible to mix in your own methods to the Element object, which you can later use as methods of extended elements |
adjacent() | Finds all siblings of the current element that match the given selector(s). |
ancestors() | Collects all of element's ancestors and returns them as an array of extended elements. |
childElements() | Collects all of the element's children and returns them as an array of extended elements. |
classNames() | Deprecated. Returns a new instance of ClassNames, an Enumerable object used to read and write CSS class names of element. |
cleanWhitespace() | Removes all of element's text nodes which contain only whitespace. Returns element. |
clonePosition() | Clones the position and/or dimensions of source onto element as defined by the optional argument options. |
cumulativeOffset() | Returns the offsets of element from the top left corner of the document. |
cumulativeScrollOffset() | Calculates the cumulative scroll offset of an element in nested scrolling containers. |
descendantOf() | Checks if element is a descendant of ancestor. |
descendants() | Collects all of element's descendants and returns them as an array of extended elements. |
down() | 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. |
empty() | Tests whether element is empty (i.e. contains only whitespace). |
extend() | Extends element with all of the methods contained in Element.Methods and Element.Methods.Simulated. |
fire() | Fires a custom event with the current element as its target. |
firstDescendant() | Returns the first child that is an element. This is opposed to firstChild DOM property which will return any node. |
getDimensions() | Finds the computed width and height of element and returns them as key/value pairs of an object. |
getElementsByClassName | 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 $$(). |
getElementsBySelector | 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 $$(). |
getHeight() | Finds and returns the computed height of element. |
getOffsetParent() | Returns element's closest positioned ancestor. If none is found, the body element is returned. |
getStyle() | Returns the given CSS property value of element. property can be specified in either of its CSS or camelized form. |
getWidth() | Finds and returns the computed width of element. |
hasClassName() | Checks whether element has the given CSS className. |
hide() | Hides and returns element. |
identify() | Returns element's id attribute if it exists, or sets and returns a unique, auto-generated id. |
immediateDescendants() | Deprecated. Collects all of the element's immediate descendants (i.e. children) and returns them as an array of extended elements. Please use childElements(). |
insert() | Inserts content before, after, at the top of, or at the bottom of element. |
inspect() | Returns the debug-oriented string representation of element. |
makeClipping() | Simulates the poorly supported CSS clip property by setting element's overflow value to 'hidden'. Returns element. |
makePositioned() | 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. |
match() | Checks if element matches the given CSS selector. |
next() | Returns element's following sibling that matches the given cssRule. |
nextSiblings() | Collects all of element's next siblings and returns them as an array of extended elements. |
observe() | Registers an event handler on element and returns element. |
positionedOffset () | Returns element's offset relative to its closest positioned ancestor |
previous () | Returns element's previous sibling that matches the given cssRule. |
previousSiblings () | Collects all of element's previous siblings and returns them as an array of extended elements. |
readAttribute () | Returns the value of element's attribute or null if attribute has not been specified. |
recursivelyCollect () | Recursively collects elements whose relationship is specified by property |
relativize () | Turns element into an relatively-positioned element without changing its position in the page layout. |
remove () | Completely removes element from the document and returns it. |
removeClassName () | Removes element's CSS className and returns element. |
replace () | Replaces element by the content of the html argument and returns the removed element. |
scrollTo () | Scrolls the window so that element appears at the top of the viewport. Returns element. |
select () | Takes an arbitrary number of CSS selectors (strings) and returns an array of extended descendants of element that match any of them. |
setOpacity () | Sets the visual opacity of an element while working around inconsistencies in various browsers. |
setStyle () | Modifies element's CSS style properties. |
show () | Displays and returns element. |
siblings () | Collects all of element's siblings and returns them as an array of extended elements. |
stopObserving () | Unregisters handler and returns element. |
toggle () | Toggles the visibility of element. |
toggleClassName () | Toggles element's CSS className and returns element. |
undoClipping () | Sets element's CSS overflow property back to the value it had before Element.makeClipping() was applied. Returns element. |
undoPositioned () | Sets element back to the state it was before Element.makePositioned was applied to it. Returns element. |
up() | Returns element's first ancestor that matches the given cssRule. |
update() | Replaces the content of element with the provided newContent argument and returns element. |
viewportOffset() | Returns the X/Y coordinates of element relative to the viewport. |
visible() | Returns a Boolean indicating whether or not element is visible |
wrap() | Wraps an element inside another, then returns the wrapper. |
writeAttribute() | Adds, specifies or removes attributes passed as either a hash or a name/value pair. |