Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An element data- attribute API for Mootools
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test support for automatic json conversion support for automatic json conversion
data-mootools.png fix to documentation
package.yml amd module if requirejs available



A poly-fill that provides an easy API for accessing all data- attributes on an element. It emulates the .data functionality found in jQuery that grabs any HTML5 data- attributes from an element and makes them available for future reference without further DOM access.

How to use

This is an element shortcut (prototype method) that stores the attributes within element storage after it 'normalises' them. Normalising being camel-casing - think CSS attributes vs .style collection keys. So, data-this-name will become thisName as key.

Several examples:

    // eg markup: <a href='#' data-title='hi there' data-tip-position='left' data-json='{"hi":"there"}'>link</a>

    // make data attributes in all links available to elements via storage

    // read something from storage - return data-title

    // read json from storage - return data-json
    typeof document.getElement("a").data("json") == 'object';

    // reference json props
    document.getElement("a").data("json").hi; // "there"

    // read something from storage - return data-tip-position

    // many ways to access dynamically:"tipPosition") =="tip-position"); // true"tipPosition") =="data-tip-position"); // true

    // static collection
    var data =;
    data['tipPosition'] == element.get("data-tip-position"); // true

    // get an element, set a data attribute and force-refresh when getting it
    document.getElement("a").set("data-title", "Simon says").data("title", true);


A full suite of tests is provided based upon node / Buster.js - see the /test directory and the there for further reference.

Something went wrong with that request. Please try again.