Possible Duplicate:
How does jQuery .data() work?
In jQuery, .data
reads the values of HTML5 data-*
attributes but when you set/update the values with the data
function, it doesn't change the attribute.
<div id="first" data-foo="attr value" > </div>
var attr = $('#first').data('foo');
alert(attr); // alerts: attr value
$('#first').data('foo', 'data value');
var data = $('#first').data('foo');
alert(data); //alerts: data value
var attrAgain = $('#first').attr('data-foo');
alert(attrAgain); // alerts: attr value
Where does jQuery store the values? In the docs it is written:
The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).
But where? I'm trying to understand how expensive using the .data
function is.
How can I reach those values without the .data
function?