Description: Store arbitrary data associated with the specified element. Returns the value that was set.
- This method does not accept any arguments.
When working with jQuery Mobile, jqmData should be used in place of jQuery core's
data method (note that this includes
$.fn.removeData, and the
$.hasData utilities), as they automatically incorporate getting and setting of namespaced data attributes (even if no namespace is currently in use).
Note: jqmData is deprecated as of version 1.5 and will be removed in version 1.6.
- See jQuery's data method
jqmData()with no argument will return
undefined. This behavior is subject to change in future versions.
When finding elements by their jQuery Mobile data attribute, please use the custom selector
:jqmData(). It automatically incorporates namespaced data attributes into the lookup when they are in use. For example, instead of calling
$("div[data-role='page']"), you should use
$("div:jqmData(role='page')"), which internally maps to
$("div[data-"+ $.mobile.ns +"role='page']")without forcing you to concatenate a namespace into your selectors manually.
One exception to this rule is selecting on namespaced data attributes with URL values, e.g the
:jqmData(url)that jQuery Mobile uses to track where a page came from. This is because the selector requires a closing parentheses but the parentheses is also valid URL character.