How is it possible to pass an array of elements as well as keeping the data
attributes using jQuery? currently I've got the following:
$('body').on('click', '.selectItem', function() {
data: {
'hash': $(this).data("hash"),
'id': $(this).data("id"),
'inspect': $(this).data("inspect"),
'stickers': $(this).data("stickers")
}
});
How would I be able to do something like this?
$('.getItems').click(function(event) {
data: {
'items': $('.selectItem').andAttributes().toArray()
}
});
I'm guessing I could do something like a foreach
& then add them into an array for each element, but doesn't jQuery have a simple solution?
My expected result from doing something like this $('.selectItem').andAttributes().toArray()
would be something like:
{
0: {
'hash': $(this).data("hash"),
'id': $(this).data("id"),
'inspect': $(this).data("inspect"),
'stickers': $(this).data("stickers")
},
1: {
'hash': $(this).data("hash"),
'id': $(this).data("id"),
'inspect': $(this).data("inspect"),
'stickers': $(this).data("stickers")
}
2: {
'hash': $(this).data("hash"),
'id': $(this).data("id"),
'inspect': $(this).data("inspect"),
'stickers': $(this).data("stickers")
}
etc....
}