# Yahoo! UI Library

### node 3.0.0b1

Yahoo! UI Library > node > NodeList
Search:
Filters
Show Private Show Protected Show Deprecated

## Class NodeList

The NodeList class provides a wrapper for manipulating DOM NodeLists. NodeList properties can be accessed via the set/get methods. Use Y.all() to retrieve NodeList instances.

### Constructor

NodeList `( )`

### Methods

#### addClass

`void addClass ( className )`
Adds a class name to each node.

Parameters:
  `className <String>` the class name to add to the node's class attribute

Returns: `void`

Chainable: This method is chainable.

#### after

`Object after ( type , fn , context )`
Applies an event listens to each Node bound to the NodeList. The handler is called only after all on() handlers are called and the event is not prevented.

Parameters:
  `type <String>` The event being listened for
  `fn <Function>` The handler to call when the event fires
  `context <Object>` The context to call the handler with. Default is the NodeList instance.

Returns: `Object`
  Returns an event handle that can later be use to detach().

#### append

`void append ( )`
Called on each Node instance

Returns: `void`

#### detach

`void detach ( )`
Called on each Node instance

Returns: `void`

#### detachAll

`void detachAll ( )`
Called on each Node instance

Returns: `void`

#### each

`void each ( fn , context )`
Applies the given function to each Node in the NodeList.

Parameters:
  `fn <Function>` The function to apply. It receives 3 arguments: the current node instance, the node's index, and the NodeList instance
  `context <Object>` optional An optional context to apply the function with Default context is the current Node instance

Returns: `void`

Chainable: This method is chainable.

#### even

`NodeList even ( )`
Creates a new NodeList containing all nodes at even indices (zero-based index), including zero.

Returns: `NodeList`
  NodeList containing the updated collection

#### 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

#### getAttribute

`string getAttribute ( name )`
Allows getting attributes on DOM nodes, normalizing in some cases. This passes through to the DOM node, allowing for custom attributes.

Parameters:
  `name <string>` The attribute name

Returns: `string`
  The attribute value

#### getComputedStyle

`Array getComputedStyle ( attr )`
Returns an array of the computed value for each node.

Parameters:
  `attr <String>` The style attribute to retrieve.

Returns: `Array`
  The computed values for each node.

#### getStyle

`Array getStyle ( attr )`
Returns an array of values for each node.

Parameters:
  `attr <String>` The style attribute to retrieve.

Returns: `Array`
  The current values of the style property for the element.

#### hasClass

`Array hasClass ( className )`
Determines whether each node has the given className.

Parameters:
  `className <String>` the class name to search for

Returns: `Array`
  An array of booleans for each node bound to the NodeList.

#### indexOf

`Int indexOf ( node )`
Returns the index of the node in the NodeList instance or -1 if the node isn't found.

Parameters:
  `node <Y.Node || DOMNode>` the node to search for

Returns: `Int`
  the index of the node value or -1 if not found

#### insert

`void insert ( )`
Called on each Node instance

Returns: `void`

#### 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.

#### NodeList.getDOMNodes

`static Array NodeList.getDOMNodes ( node )`
Retrieves the DOM nodes bound to a NodeList instance

Parameters:
  `node <Y.NodeList>` The NodeList instance

Returns: `Array`
  The array of DOM nodes bound to the NodeList

#### odd

`NodeList odd ( )`
Creates a new NodeList containing all nodes at odd indices (zero-based index).

Returns: `NodeList`
  NodeList containing the updated collection

#### on

`Object on ( type , fn , context )`
Applies an event listens to each Node bound to the NodeList.

Parameters:
  `type <String>` The event being listened for
  `fn <Function>` The handler to call when the event fires
  `context <Object>` The context to call the handler with. Default is the NodeList instance.

Returns: `Object`
  Returns an event handle that can later be use to detach().

#### plug

`void plug ( )`
Called on each Node instance

Returns: `void`

#### prepend

`void prepend ( )`
Called on each Node instance

Returns: `void`

#### remove

`void remove ( )`
Called on each Node instance

Returns: `void`

#### removeClass

`void removeClass ( className )`
Removes a class name from each node.

Parameters:
  `className <String>` the class name to remove from the node's class attribute

Returns: `void`

Chainable: This method is chainable.

#### replaceClass

`void replaceClass ( oldClassName , newClassName )`
Replace a class with another class for each node. 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.

#### set

`void set ( )`
Called on each Node instance

Returns: `void`

#### setAttribute

`void setAttribute ( name , value )`
Allows setting attributes on DOM nodes, normalizing in some cases. This passes through to the DOM node, allowing for custom attributes.

Parameters:
  `name <string>` The attribute name
  `value <string>` The value to set

Returns: `void`

Chainable: This method is chainable.

#### setContent

`void setContent ( )`
Called on each Node instance

Returns: `void`

#### setStyle

`void setStyle ( attr , val )`
Sets a style property on each 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 each node.

Parameters:
  `hash <Object>` An object literal of property:value pairs.

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.

#### some

`Boolean some ( fn , context )`
Executes the function once for each node until a true value is returned.

Parameters:
  `fn <Function>` The function to apply. It receives 3 arguments: the current node instance, the node's index, and the NodeList instance
  `context <Object>` optional An optional context to execute the function from. Default context is the current Node instance

Returns: `Boolean`
  Whether or not the function returned true for any node.

#### 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.

#### unplug

`void unplug ( )`
Called on each Node instance

Returns: `void`

Copyright © 2009 Yahoo! Inc. All rights reserved.