1/* html */
2<a data-id="123">link</a>
3
4/* js */
5$(this).attr("data-id") // returns string "123"
6
7$(this).data("id") // returns number 123 (jQuery >= 1.4.3 only)
1$( some_item ).attr( "id", "some-id" );
2// for setting multiple attributes, it's similar to the css() property. However, quotes are not always required for attr()
3$( some_item ).attr({
4 id: "some-id",
5 // or others.
6 title: "Opens in a new window",
7 // attributes which contain dash(-), should be covered in quotes.
8 "data-value": "internal link"
9});
1$( "div" ).data( "role" ) === "page";
2$( "div" ).data( "lastValue" ) === 43;
3$( "div" ).data( "hidden" ) === true;
4$( "div" ).data( "options" ).name === "John";
5
1<div data-role="page" data-last-value="43" data-hidden="true" data-options='{"name":"John"}'></div>
2