| Module | Document |
| In: |
lib/source/redshift/document.rb
|
The Document object enables access to top-level HTML elements like , , and .
Document also provides “DOM-ready” functionality with Document.ready? and element-finding functionality through the powerful Document.[] method.
The first form returns the Element identified by the id str (e.g. ‘my_id‘), or nil if no such element is found. The second form returns the array of elements identified by the selector str. The third form returns the array of elements found by calling Document.[] on each arg. The fourth form returns element unchanged.
The first form returns the Element identified by the string “id“, or nil if no such element is found.
Document['#content'] #=> #<Element: DIV id="content">
The second form returns the array of Element objects that match the string “selector“, which takes the format of a CSS3 selector. See www.w3.org/TR/css3-selectors/ for details.
Available Selectors Document[str] in its second form takes a selector string and scans the document returing an array of any elements that match the selector string.
The selectors string takes the format of a CSS3 selector: www.w3.org/TR/css3-selectors/
Class Selector Returns an array of elements that
have the specified class name Document #=>
[#
Tag Selector Returns an array of elements that have the specified tag
Document[‘a’] #=> [#
When the DOM is finished loading, executes the given block, then returns nil.
Document.ready? do
puts self.title
end
produces:
"RDoc Documentation"
Walks the DOM from a particular element. The first step it talks in the walk with either be the specified start_relation or the specified path. If ‘all’ is set to false, the walk will termiante and return the single element. Otherwise, it will continue the walk until it has reached the end of the specified path. The walk will then termiante and return an array of all elements on the path.
if an optional match_selector is provided, only element(s) that match the selector can be returned
Examples: Document.walk(my_element, ‘parentNode’, nil, nil, false) will go down the parentNode path of my_element, starting at the my_element, and return just a single element
Document.walk(my_element, ‘parentNode’, nil, nil, true) will go down the parentNode path of my_element, starting at my_element, and return an array of all elements on the parentNode path
Document.walk(my_element, ‘nextSibling’, ‘firstChild’, nil, true) will go down the nextSibling path of my_element, starting at my_element’s firstChild and return an array of all elements on the nextSibling path from that starting point.
Document.walk(my_element, ‘nextSibling’, ‘firstChild’, ’.my_class’, true) will go down the nextSibling path of my_element, starting at my_element’s firstChild and return an array of all elements on the nextSibling path from that starting point that have the class ‘my_class‘