W3cubDocs

/jQuery Mobile

jqmData()

.jqmData()Returns: Object

Description: Store arbitrary data associated with the specified element. Returns the value that was set.

  • .jqmData()

    • 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.data, $.fn.removeData, and the $.data, $.removeData, and $.hasData utilities), as they automatically incorporate getting and setting of namespaced data attributes (even if no namespace is currently in use).

Arguments:
See jQuery's data method
Note:
Calling jqmData() with no argument will return undefined. This behavior is subject to change in future versions.
Also:

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.

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquerymobile.com/jqmData