The jqmData()
and jqmRemoveData()
methods are available to add or remove data attributes to the elements of a jQuery mobile app. They automatically handle custom namespaces. This recipe shows you how to use these methods.
Copy the full code of this recipe from the code/09/jqmdata
source folder. You can launch this code by using the URL: http://localhost:8080/09/jqmdata/main.html
.
Add the following script to
main.html
before includingjquery.
mobile.js
:$(document).bind("mobileinit", function() { $.mobile.ns = "my-"; });
Add two text inputs and a button to the page, as follows:
<div data-my-role="content"> <div data-role="fieldcontain"> <label for="pgtheme">Page Theme : </label> <input type="text" id="pgtheme" /> </div> <div data-role="fieldcontain"> <label for="customdata">Custom Data : </label> <input type="text" id="customdata" /> </div>...