# Yahoo! UI Library

### node 3.3.0

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 `( )`

### Properties

#### _nodes - `private object`

The underlying array of DOM nodes bound to the Y.NodeList instance

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

Chainable: This method is chainable.

#### after

`Object after ( type , fn , context )`
Applies an event listener 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

#### concat

`NodeList concat ( valueN )`
Returns a new NodeList combining the given NodeList(s)

Parameters:
  `valueN <NodeList | Array>` Arrays/NodeLists and/or values to concatenate to the resulting NodeList

Returns: `NodeList`
  A new NodeList comprised of this NodeList joined with the input.

#### destroy

`void destroy ( )`
Called on each Node instance

#### detach

`void detach ( )`
Called on each Node instance

#### detachAll

`void detachAll ( )`
Called on each Node instance

#### each

`void 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

Chainable: This method is chainable.
Deprecated Use NodeList

#### empty

`void empty ( )`
Called on each Node instance

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

#### generateID

`String generateID ( )`
Applies a unique ID to each node if none exists

Returns: `String`
  The existing or generated ID

#### get

`void get ( )`
Called on each Node instance

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

#### hide

`void hide ( name , config , callback )`
Hides each node. If the "transition" module is loaded, hide optionally animates the hiding of the node using either the default transition effect ('fadeOut'), or the given named effect.

Parameters:
  `name <String>` A named Transition effect to use as the show effect.
  `config <Object>` Options to use with the transition.
  `callback <Function>` An optional function to run after the transition completes.

Chainable: This method is chainable.

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

#### isEmpty

`Boolean isEmpty ( )`
Determines if the instance is bound to any nodes

Returns: `Boolean`
  Whether or not the NodeList is bound to any nodes

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

Deprecated Use NodeList

#### modulus

`NodeList modulus ( n , r )`
Creates a new NodeList containing all nodes at every n indices, where remainder n % index equals r. (zero-based index).

Parameters:
  `n <Int>` The offset to use (return every nth node)
  `r <Int>` An optional remainder to use with the modulus operation (defaults to zero)

Returns: `NodeList`
  NodeList containing the updated collection

#### NodeList.getDOMNodes

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

Parameters:
  `nodelist <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 , arg* )`
Applies an event listener 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.
  `arg* <Object} context The context to call the handler with. param {mixed>` 0..n additional arguments to supply to the subscriber when the event fires.

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

#### once

`Object once ( type , fn , context )`
Applies an one-time event listener 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().

#### pop

`Node pop ( )`
Removes the first last from the NodeList and returns it.

Returns: `Node`
  The last item in the NodeList.

#### prepend

`void prepend ( )`
Called on each Node instance

#### push

`void push ( nodeN )`
Adds the given Node(s) to the end of the NodeList.

Parameters:
  `nodeN <Node | DOMNode>` One or more nodes to add to the end of the NodeList.

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

Deprecated Use one()

#### 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 all()

#### refresh

`void refresh ( )`
Reruns the initial query, when created using a selector query
Chainable: This method is chainable.

#### remove

`void remove ( )`
Called on each Node instance

#### removeAttribute

`void removeAttribute ( name )`
Allows for removing attributes on DOM nodes. This passes through to the DOM node, allowing for custom attributes.

Parameters:
  `name <string>` The attribute to remove

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

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

Chainable: This method is chainable.

#### set

`void set ( )`
Called on each Node instance

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

Chainable: This method is chainable.

#### setContent

`void setContent ( )`
Called on each Node instance

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

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.

Chainable: This method is chainable.

#### shift

`Node shift ( )`
Removes the first item from the NodeList and returns it.

Returns: `Node`
  The first item in the NodeList.

#### show

`void show ( name , config , callback )`
Makes each node visible. If the "transition" module is loaded, show optionally animates the showing of the node using either the default transition effect ('fadeIn'), or the given named effect.

Parameters:
  `name <String>` A named Transition effect to use as the show effect.
  `config <Object>` Options to use with the transition.
  `callback <Function>` An optional function to run after the transition completes.

Chainable: This method is chainable.

#### size

`Int size ( )`
Returns the current number of items in the Node.

Returns: `Int`
  The number of items in the Node.

Deprecated Use NodeList

#### slice

`NodeList slice ( begin , end )`
Returns a new NodeList comprising the Nodes in the given range.

Parameters:
  `begin <Number>` Zero-based index at which to begin extraction. As a negative index, start indicates an offset from the end of the sequence. slice(-2) extracts the second-to-last element and the last element in the sequence.
  `end <Number>` Zero-based index at which to end extraction. slice extracts up to but not including end. slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3). As a negative index, end indicates an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence. If end is omitted, slice extracts to the end of the sequence.

Returns: `NodeList`
  A new NodeList comprised of this NodeList joined with the input.

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

#### splice

`NodeList splice ( index , howMany )`
Changes the content of the NodeList, adding new elements while removing old elements.

Parameters:
  `index <Number>` Index at which to start changing the array. If negative, will begin that many elements from the end.
  `howMany <Number>` An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed. In this case, you should specify at least one new element. If no howMany parameter is specified (second syntax above, which is a SpiderMonkey extension), all elements after index are removed. {Node | DOMNode| element1, ..., elementN The elements to add to the array. If you don't specify any elements, splice simply removes elements from the array.

Returns: `NodeList`
  The element(s) removed.

#### toFrag

`toFrag ( )`
Creates a documenFragment from the nodes bound to the NodeList instance

Returns: ``
  Node a Node instance bound to the documentFragment

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

Chainable: This method is chainable.

#### transition

`void transition ( config , callback )`
Animate one or more css properties to a given value. Requires the "transition" module.

    example usage:
    Y.all('.demo').transition({
    duration: 1, // in seconds, default is 0.5
    easing: 'ease-out', // default is 'ease'
    delay: '1', // delay start for 1 second, default is 0
    height: '10px',
    width: '10px',
    opacity: { // per property
    value: 0,
    duration: 2,
    delay: 2,
    easing: 'ease-in'
    }
    });

Parameters:
  `config <Object>` An object containing one or more style properties, a duration and an easing.
  `callback <Function>` A function to run after the transition has completed. The callback fires once per item in the NodeList.

Chainable: This method is chainable.

#### unwrap

`void unwrap ( )`
Removes the parent node from node in the list.
Chainable: This method is chainable.

#### wrap

`void wrap ( html )`
Wraps the given HTML around each node.

Parameters:
  `html <String>` The markup to wrap around the node.

Chainable: This method is chainable.

#### Y.get

`static void Y.get ( node , doc )`
Returns a single Node instance bound to the node or the first element matching the given selector.

Parameters:
  `node <String | HTMLElement>` a node or Selector
  `doc <Y.Node || HTMLElement>` an optional document to scan. Defaults to Y.config.doc.

Deprecated Use Y.one

Copyright © 2011 Yahoo! Inc. All rights reserved.