I think the best way is to use HTML5 data - * Attributes and jQuery.data (). It will probably have a better way to store data in embedded HTML elements and update them to the latest technologies, so you can lean back and be productive
<div id="myDiv" data-my-var="my-var-value"></div>
can be used in JavaScript: (jQuery required)
console.log( $( '#myDiv' ).data( 'my-var' ) )
Edit: and set this as
$( '#myDiv' ).data( 'my-var', 'my-new-var-value' );
which will also update the data- * attribute in this case
Torben
source share