HTML5 custom data attributes
The code examples we've seen so far in this chapter have all used JavaScript APIs exposed by plugins in order to invoke the plugin functionality. We've seen jQuery object methods, global functions, and custom selectors as some ways that plugins offer their services to our scripts. The jQuery Mobile library has these entry points as well, but the most common way of interacting with it is instead via HTML5 data attributes.
The HTML5 specification allows us to insert any attribute we want into an element, so long as the attribute is prefixed by data-. Such attributes are completely ignored when rendering the page, but are available to us in our jQuery scripts. When we include jQuery Mobile on a page, the script scans ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access