Is it possible to loop through a data() object?
Suppose this is my code:
$('#mydiv').data('bar','lorem');
$('#mydiv').data('foo','ipsum');
$('#mydiv').data('cam','dolores');
How do I loop through this? Can each() be used for this?
jQuery stores all the data information in the jQuery.cache internal variable. It is possible to get all the data associated with a particular object with this simple but helpful plugin:
With this in place, you can do this:
You could just use matt b's suggestion but this is how to do it with what you have right now. |
|||||
|
This will iterate through each property in 'this' element's data object. |
||||
|
Tested with jQuery 1.4 and tips from @user292614 the following works:
|
|||
|
I just tried this but needed some extra data values. If you also got this "problem" then the following should work.
then you can simply extend with the value id
|
|||
|