size: 0.5k (minified)
A little jQuery extension to attach behavior to data-role attributes, instead of classnames.
See this blog post for some background information.
You can install it easily with bower:
bower install dataroles.js
$.findByRole('show-alert')
is equivalent to:
$("[data-role~='show-alert']")
$("body").findByRole('show-alert')
is equivalent to
$("body").find("[data-role~='show-alert']")
parentsByRole('role')
->parents("[data-role~='role']")
siblingsByRole('role')
->siblings("[data-role~='role']")
- etc..
All standard jQuery traversal methods are wrapped like this.
.hasRole(role)
is quivalent to .is("[data-role~='role']")
multiple roles per data-role attribute are supported (uses the ~=
operator internally)