<div class="person" data-year-of-birth="1952">The Hoff</div>
If a Web page wanted an element to represent a space ship, e.g. as part of a game, it would have to use the class attribute along with data-* attributes:
<div class="spaceship" data-ship-id="92432"
data-weapons="laser 2" data-shields="50%"
data-x="30" data-y="10" data-z="90">
<button class="fire"
onclick="spaceships[this.parentNode.dataset.shipId].fire()">
Fire
</button>
</div>
interface DOMStringMap {
getter DOMString (DOMString name);
setter creator void (DOMString name, DOMString value);
deleter void (DOMString name);
};
<div data-foo-bar="Hello World"></div>
<script>
$('div[data-foo-bar]').each(function(){
// Obtain data
var dataFnc = $(this).data.bind($(this));
console.log(dataFnc('fooBar'));
// Modify data
dataFnc('fooBar', dataFnc('fooBar').split('').reverse().join(''));
console.log(dataFnc('fooBar'));
console.log($(this).attr('data-foo-bar'));
});
</script>
if ( typeof data === "string" ) { try { data = data === "true" ? true : data === "false" ? false : data === "null" ? null : // Only convert to a number if it doesn't change the string
+data + "" === data ? +data : rbrace.test( data ) ? jQuery.parseJSON( data ) : data;
} catch( e ) {}
// Make sure we set the data so it isn't changed later
jQuery.data( elem, key, data );
} else { data = undefined; }