all is said in the title, I want to get from an element all the data set using the data method.
(ultimately I want to copy that data over to a newly created element)
thanks for any help !
Olivier
all is said in the title, I want to get from an element all the data set using the data method.
(ultimately I want to copy that data over to a newly created element)
thanks for any help !
Olivier
This has been asked before. My answer from there, since it is a good question:
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:
jQuery.fn.allData = function() {
var intID = jQuery.data(this.get(0));
return(jQuery.cache[intID]);
};
With this in place, you can do this:
$('#myelement').data('test1','yay1')
.data('test2','yay2')
.data('test3','yay3');
$.each($('#myelement').allData(), function(key, value) {
alert(key + "=" + value);
});
Alternatively, you can simply store an object:
$('#myelement').data('data', {test1:'yay1',test2:'yay2',test3:'yay3'});