跳到主要内容

data

data(name) ⇒ value
data(name, value) ⇒ self

Read or write data-* DOM attributes. Behaves like attr, but prepends data- to the attribute name.

When reading attribute values, the following conversions apply: v1.0+

  • "true", "false", and "null" are converted to corresponding types;
  • number values are converted to actual numeric types;
  • JSON values are parsed, if it's valid JSON;
  • everything else is returned as string.

Zepto's basic implementation of `data()` only stores strings. To store arbitrary objects, include the optional "data" module in your custom build of Zepto.