can.data

  • function
 

Associate data with or retrieve data from DOM nodes.

can.data(nodeList, key, value)

Parameters

  1. nodeList {NodeList}

    The list of nodes to add this data to.

  2. key {String}

    The key to store this data under.

  3. value {*}

    The data to store.

can.data(nodeList, key)

Parameters

  1. nodeList {NodeList}

    The list of nodes data was stored under.

  2. key {String}

    The key to retrieve.

Returns

{*}

The data stored under key.

can.data enables the associatation of arbitrary data with DOM nodes and JavaScript objects.

Setting Data

can.data( can.$('#elm'), key, value )

  • wrappedNodeList node list to associate data to.
  • key string name of the association.
  • value tdata value; it can be any Javascript type including Array or Object.

Accessing Data

can.data( can.$('#elm'), key )

  • wrappedNodeList node list to retrieve association data from.
  • key string name of the association.

Due to the way browsers security restrictions with plugins and external code, the data method cannot be used on object (unless it's a Flash plugin), applet or embed elements.