Understanding jQuery's Data API's
jQuery's Core Team Member, Dave Methvin has a great write up on LearningjQuery.com called "Using jQuery's Data API". He walks us through the beginning thoughts on what the .data() API was meant for, a DOM based In-Memory storage, to how it evolved into reading the data attribute in HTML5. Dave outlines 5 rules of the road for using .data():
- Only the
.data()
API reads HTML5data-*
attributes, and it does so once. - The
.data()
API converts HTML5data-*
values to Javascript types whenever possible. - The lower-level
jQuery.data()
API does not read HTML5data-*
attributes. - No jQuery data API ever changes HTML5
data-*
attributes. - All
data-*
names are stored in camelCase in the jQuery data object, using W3C rules.
You can read more about the history and the rules of the road over at Learning jQuery.