Yahoo! UI Library

node  3.0.0pr2

Yahoo! UI Library > node > Node
Search:
 
Filters

Class Node

The Node class provides a wrapper for manipulating DOM Nodes. Node properties can be accessed via the set/get methods. Use Y.get() to retrieve Node instances. NOTE: Node properties are accessed using the set and get methods.

Constructor

Node ( )

Properties

children - NodeList

Returns a NodeList instance.

docHeight - {Int}

Document height

docScrollX - {Int}

Amount page has been scroll vertically

docScrollY - {Int}

Amount page has been scroll horizontally

region - Node

Returns a region object for the node

text - String

Normalizes nodeInnerText and textContent.

viewportRegion - Node

Returns a region object for the node's viewport

winHeight - {Int}

Returns the inner height of the viewport (exludes scrollbar).

winWidth - {Int}

Returns the inner width of the viewport (exludes scrollbar).

Methods

addClass

void addClass ( className )
Adds a class name to the node.
Parameters:
className <String> the class name to add to the node's class attribute
Returns: void
Chainable: This method is chainable.

ancestor

Node ancestor ( fn )
Returns the nearest ancestor that passes the test applied by supplied boolean method.
Parameters:
fn <String | Function> A selector or boolean method for testing elements. If a function is used, it receives the current node being tested as the only argument.
Returns: Node
The matching Node instance or null if not found

appendChild

Node appendChild ( node )
Passes through to DOM method.
Parameters:
node <HTMLElement | Node> Node to be appended
Returns: Node
The appended node

attach

void attach ( type , fn , arg )
Attaches a DOM event handler.
Parameters:
type <String> The type of DOM Event to listen for
fn <Function> The handler to call when the event fires
arg <Object> An argument object to pass to the handler
Returns: void

blur

void blur ( )
Passes through to DOM method.
Returns: void
Chainable: This method is chainable.

cloneNode

Node cloneNode ( node )
Passes through to DOM method.
Parameters:
node <HTMLElement | Node> Node to be cloned
Returns: Node
The clone

compareTo

Boolean compareTo ( refNode )
Compares nodes to determine if they match. Node instances can be compared to each other and/or HTMLElements.
Parameters:
refNode <HTMLElement | Node> The reference node to compare to the node.
Returns: Boolean
True if the nodes match, false if they do not.

contains

Boolean contains ( needle )
Determines whether the ndoe is an ancestor of another HTML element in the DOM hierarchy.
Parameters:
needle <Node | HTMLElement> The possible node or descendent
Returns: Boolean
Whether or not this node is the needle its ancestor

create

Node create ( html )
Creates a Node instance from HTML string
Parameters:
html <String|Array> The string of html to create
Returns: Node
A new Node instance

detach

void detach ( type , fn )
Detaches a DOM event handler.
Parameters:
type <String> The type of DOM Event
fn <Function> The handler to call when the event fires
Returns: void

each

NodeList each ( fn , context )
Applies the given function to each Node in the NodeList.
Parameters:
fn <Function> The function to apply
context <Object> optional An optional context to apply the function with Default context is the NodeList instance
Returns: NodeList
NodeList containing the updated collection
Chainable: This method is chainable.

filter

NodeList filter ( selector )
Filters the NodeList instance down to only nodes matching the given selector.
Parameters:
selector <String> The selector to filter against
Returns: NodeList
NodeList containing the updated collection

focus

void focus ( )
Passes through to DOM method.
Returns: void
Chainable: This method is chainable.

get

any get ( prop )
Get the value of the property/attribute on the HTMLElement bound to this Node. Only strings/numbers/booleans are passed through unless a GETTER exists.
Parameters:
prop <String> Property to get
Returns: any
Current value of the property

getAttribute

String getAttribute ( attribute )
Passes through to DOM method.
Parameters:
attribute <String> The attribute to retrieve
Returns: String
The current value of the attribute

getComputedStyle

String getComputedStyle ( attr )
Returns the computed value for the given style property.
Parameters:
attr <String> The style attribute to retrieve.
Returns: String
The computed value of the style property for the element.

getElementsByTagName

NodeList getElementsByTagName ( tagName )
Passes through to DOM method.
Parameters:
tagName <String> The tagName to collect
Returns: NodeList
A NodeList representing the HTMLCollection

getStyle

String getStyle ( attr )
Returns the style's current value.
Parameters:
attr <String> The style attribute to retrieve.
Returns: String
The current value of the style property for the element.

getX

Int getX ( )
Gets the current position of the node in page coordinates. Nodes must be part of the DOM tree to have page coordinates (display:none or nodes not appended return false).
Returns: Int
The X position of the node

getXY

Array getXY ( )
Gets the current position of the node in page coordinates. Nodes must be part of the DOM tree to have page coordinates (display:none or nodes not appended return false).
Returns: Array
The XY position of the node

getY

Int getY ( )
Gets the current position of the node in page coordinates. Nodes must be part of the DOM tree to have page coordinates (display:none or nodes not appended return false).
Returns: Int
The Y position of the node

hasAttribute

Boolean hasAttribute ( attribute )
Passes through to DOM method.
Parameters:
attribute <String> The attribute to test for
Returns: Boolean
Whether or not the attribute is present

hasChildNodes

Boolean hasChildNodes ( )
Passes through to DOM method.
Returns: Boolean
Whether or not the node has any childNodes

hasClass

Boolean hasClass ( className )
Determines whether the node has the given className.
Parameters:
className <String> the class name to search for
Returns: Boolean
Whether or not the node has the given class.

inDoc

Boolean inDoc ( doc )
Determines whether the node is appended to the document.
Parameters:
doc <Node|HTMLElement> optional An optional document to check against. Defaults to current document.
Returns: Boolean
Whether or not this node is appended to the document.

inRegion

Object inRegion ( node2 , all , altRegion )
Determines whether or not the node is within the giving region.
Parameters:
node2 <Node|Object> The node or region to compare with.
all <Boolean> Whether or not all of the node must be in the region.
altRegion <Object> An alternate region to use (rather than this node's).
Returns: Object
An object representing the intersection of the regions.

insertBefore

Node insertBefore ( newNode , refNode )
Passes through to DOM method.
Parameters:
newNode <HTMLElement | Node> Node to be appended
refNode <HTMLElement | Node> Node to be inserted before
Returns: Node
The inserted node

intersect

Object intersect ( node2 , altRegion )
Compares the intersection of the node with another node or region
Parameters:
node2 <Node|Object> The node or region to compare with.
altRegion <Object> An alternate region to use (rather than this node's).
Returns: Object
An object representing the intersection of the regions.

inViewportRegion

Boolean inViewportRegion ( )
Determines whether or not the node is currently visible in the viewport.
Returns: Boolean
Whether or not the node is currently positioned within the viewport's region

item

Node item ( index )
Retrieves the Node instance at the given index.
Parameters:
index <Number> The index of the target Node.
Returns: Node
The Node instance at the given index.

next

Node next ( fn , all )
Returns the next matching sibling. Returns the nearest element node sibling if no method provided.
Parameters:
fn <String | Function> A selector or boolean method for testing elements. If a function is used, it receives the current node being tested as the only argument.
all <Boolean> optional Whether all node types should be returned, or just element nodes.
Returns: Node
Node instance or null if not found

on

void on ( type , fn , arg )
Alias for attach.
Parameters:
type <String> The type of DOM Event to listen for
fn <Function> The handler to call when the event fires
arg <Object> An argument object to pass to the handler
Returns: void

plug

void plug ( The , config )
Applies the supplied plugin to the node.
Parameters:
The <Function> plugin Class to apply
config <Object> An optional config to pass to the constructor
Returns: void
Chainable: This method is chainable.

previous

Node previous ( fn , all )
Returns the previous matching sibling. Returns the nearest element node sibling if no method provided.
Parameters:
fn <String | Function> A selector or boolean method for testing elements. If a function is used, it receives the current node being tested as the only argument.
all <Boolean> optional Whether all node types should be returned, or just element nodes.
Returns: Node
Node instance or null if not found

query

Node query ( selector )
Retrieves a Node instance of nodes based on the given CSS selector.
Parameters:
selector <string> The CSS selector to test against.
Returns: Node
A Node instance for the matching HTMLElement.

queryAll

NodeList queryAll ( selector )
Retrieves a nodeList based on the given CSS selector.
Parameters:
selector <string> The CSS selector to test against.
Returns: NodeList
A NodeList instance for the matching HTMLCollection/Array.
Deprecated Use query() which returns all matches

removeAttribute

void removeAttribute ( attribute )
Passes through to DOM method.
Parameters:
attribute <String> The attribute to be removed
Returns: void
Chainable: This method is chainable.

removeChild

Node removeChild ( node )
Passes through to DOM method.
Parameters:
node <HTMLElement | Node> Node to be removed
Returns: Node
The removed node

removeClass

void removeClass ( className )
Removes a class name from the node.
Parameters:
className <String> the class name to remove from the node's class attribute
Returns: void
Chainable: This method is chainable.

replaceChild

Node replaceChild ( node , refNode )
Passes through to DOM method.
Parameters:
node <HTMLElement | Node> Node to be inserted
refNode <HTMLElement | Node> Node to be replaced
Returns: Node
The replaced node

replaceClass

void replaceClass ( oldClassName , newClassName )
Replace a class with another class. If no oldClassName is present, the newClassName is simply added.
Parameters:
oldClassName <String> the class name to be replaced
newClassName <String> the class name that will be replacing the old class name
Returns: void
Chainable: This method is chainable.

reset

void reset ( )
Passes through to DOM method. Only valid on FORM elements
Returns: void
Chainable: This method is chainable.

scrollIntoView

void scrollIntoView ( )
Passes through to DOM method.
Returns: void
Chainable: This method is chainable.

select

void select ( )
Passes through to DOM method.
Returns: void
Chainable: This method is chainable.

set

void set ( prop , val )
Set the value of the property/attribute on the HTMLElement bound to this Node. Only strings/numbers/booleans are passed through unless a SETTER exists.
Parameters:
prop <String> Property to set
val <any> Value to apply to the given property
Returns: void
Chainable: This method is chainable.

setAttribute

void setAttribute ( attribute , The )
Passes through to DOM method.
Parameters:
attribute <String> The attribute to set
The <String> value to apply to the attribute
Returns: void
Chainable: This method is chainable.

setStyle

void setStyle ( attr , val )
Sets a style property of the node.
Parameters:
attr <String> The style attribute to set.
val <String|Number> The value.
Returns: void
Chainable: This method is chainable.

setStyles

void setStyles ( hash )
Sets multiple style properties on the node.
Parameters:
hash <Object> An object literal of property:value pairs.
Returns: void
Chainable: This method is chainable.

setX

void setX ( x )
Set the position of the node in page coordinates, regardless of how the node is positioned. The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
Parameters:
x <Int> X value for new position (coordinates are page-based)
Returns: void
Chainable: This method is chainable.

setXY

void setXY ( xy )
Set the position of the node in page coordinates, regardless of how the node is positioned. The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
Parameters:
xy <Array> Contains X & Y values for new position (coordinates are page-based)
Returns: void
Chainable: This method is chainable.

setY

void setY ( y )
Set the position of the node in page coordinates, regardless of how the node is positioned. The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
Parameters:
y <Int> Y value for new position (coordinates are page-based)
Returns: void
Chainable: This method is chainable.

size

Int size ( )
Returns the current number of items in the NodeList.
Returns: Int
The number of items in the NodeList.

submit

void submit ( )
Passes through to DOM method. Only valid on FORM elements
Returns: void
Chainable: This method is chainable.

test

boolean test ( selector )
Test if the supplied node matches the supplied selector.
Parameters:
selector <string> The CSS selector to test against.
Returns: boolean
Whether or not the node matches the selector.

toggleClass

void toggleClass ( className )
If the className exists on the node it is removed, if it doesn't exist it is added.
Parameters:
className <String> the class name to be toggled
Returns: void
Chainable: This method is chainable.

Y.all

static NodeList Y.all ( node , doc , isRoot )
Retrieves a NodeList instance for the given object/string.
Parameters:
node <HTMLCollection|Array|String> The object to wrap.
doc <document|Node> optional The document containing the node. Defaults to current document.
isRoot <boolean> optional Whether or not this node should be treated as a root node. Root nodes
Returns: NodeList
A NodeList instance for the supplied nodes.

Y.get

static Node Y.get ( node , doc , isRoot )
Retrieves a Node instance for the given query or nodes. Note: Use 'document' string to retrieve document Node instance from string
Parameters:
node <document|HTMLElement|HTMLCollection|Array|String> The object to wrap.
doc <document|Node> optional The document containing the node. Defaults to current document.
isRoot <boolean> optional Whether or not this node should be treated as a root node. Root nodes aren't allowed to traverse outside their DOM tree.
Returns: Node
A Node instance bound to the supplied node(s).


Copyright © 2008 Yahoo! Inc. All rights reserved.