AJAX Tricks and Prototype
addClassName(element, className) -> HTMLElement
Adds a CSS class to element
.
addMethods([methods])
Takes a hash of methods
and makes them available as methods of extended
elements and of the Element
object.
ancestors(element) -> [HTMLElement...]
Collects all of element
's ancestors and returns them as an array of extended elements.
classNames(element) -> [className...]
Returns a new instance of ClassNames
, an Enumerable object used to read and write class names of the element.
cleanWhitespace(element) -> HTMLElement
Removes all of element
's text nodes which contain only whitespace. Returns element
.
descendantOf(element, ancestor) -> Boolean
Checks if element
is a descendant of ancestor
.
descendants(element) -> [HTMLElement...]
Collects all of element
's descendants and returns them as an array of extended elements.
empty(element) -> Boolean
Tests whether element
is empty (i.e. contains only whitespace).
extend(element)
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.
getDimensions(element) -> {height: Number, width: Number}
Finds the computed width
and height
of element
and returns them as key/value pairs of an object.
getElementsByClassName(element, className) -> [HTMLElement...]
Fetches all of element
's descendants which have a CSS class of className
and returns them as an array of extended elements.
getElementsBySelector(element, selector...) -> [HTMLElement...]
Takes an arbitrary number of CSS selectors (strings) and returns a document-order array of extended children of element
that match any of them.
getHeight(element) -> Number
Finds and returns the computed height of element
.
getStyle(element, property) -> String | null
Returns the given CSS property value of element
. property
can be specified in either of its CSS or camelized form.
getWidth(element) -> Number
Finds and returns the computed width of element
.
hasClassName(element, className) -> Boolean
Checks whether element
has the given CSS className
.
hide(element) -> HTMLElement
Hides and returns element
.
immediateDescendants(element) -> [HTMLElement...]
Collects all of the element's immediate descendants (i.e. children) and returns them as an array of extended elements.
inspect(element) -> String
Returns the debug-oriented string representation of element
.
makeClipping(element) -> HTMLElement
Simulates the poorly supported CSS clip
property by setting element
's overflow value to 'hidden'
. Returns element
.
makePositioned(element) -> HTMLElement
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 ftp://ftp.
. Returns element
.
match(element, selector) -> Boolean
Checks if element
matches the given CSS selector
.
next(element[, cssRule][, index = 0]) -> HTMLElement | ftp://ftp.
Returns element
's following sibling (or the index'th one, if index
is specified) that matches cssRule
. If no cssRule
is provided, all following siblings are considered. If no following sibling matches these criteria, ftp://ftp.
is returned.
nextSiblings(element) -> [HTMLElement...]
Collects all of element
's next siblings and returns them as an array of extended elements.
observe(element, eventName, handler[, useCapture = false]) -> HTMLElement
Registers an event handler on element
and returns element
.
previous(element[, cssRule][, index = 0]) -> HTMLElement | ftp://ftp.
Returns element
's previous sibling (or the index'th one, if index
is specified) that matches cssRule
. If no cssRule
is provided, all previous siblings are considered. If no previous sibling matches these criteria, ftp://ftp.
is returned.
previousSiblings(element) -> [HTMLElement...]
Collects all of element
's previous siblings and returns them as an array of extended elements.
readAttribute(element, attribute) -> String | null
Returns the value of element
's attribute
or null
if attribute
has not been specified.
recursivelyCollect(element, property) -> [HTMLElement...]
Recursively collects elements whose relationship is specified by property
. property
has to be a property (a method won't do!) of element
that points to a single DOM node. Returns an array of extended elements.
remove(element) -> HTMLElement
Completely removes element
from the document and returns it.
removeClassName(element, className) -> HTMLElement
Removes element
's CSS className
and returns element
.
replace(element[, html]) -> HTMLElement
Replaces element
by the content of the html
argument and returns the removed element
.
scrollTo(element) -> HTMLElement
Scrolls the window so that element
appears at the top of the viewport. Returns element
.
setStyle(element, styles) -> HTMLElement
Modifies element
's CSS style properties. Styles are passed as a hash of property-value pairs in which the properties are specified in their camelized form.
show(element) -> HTMLElement
Displays and returns element
.
siblings(element) -> [HTMLElement...]
Collects all of element's siblings and returns them as an array of extended elements.
stopObserving(element, eventName, handler) -> HTMLElement
Unregisters handler
and returns element
.
toggle(element) -> HTMLElement
Toggles the visibility of element
.
toggleClassName(element, className) -> HTMLElement
Toggles element
’s CSS className
and returns element
.
undoClipping(element) -> HTMLElement
Sets element
's CSS overflow
property back to the value it had before Element.makeClipping() was applied. Returns element
.
undoPositioned(element) -> HTMLElement
Sets element
back to the state it was before Element.makePositioned was applied to it. Returns element
.
update(element[, newContent]) -> HTMLElement
Replaces the content of element
with the provided newContent
argument and returns element
.
visible(element) -> Boolean
Returns a Boolean
indicating whether or not element
is visible (i.e. whether its inline style
property is set to "display: none;"
).
12 of 16