This works for the first match:
var attributeValue = $({selector}).data("myAttribute");
But if I want to get values for all elements selector matches, I do the following:
var attributes = [];
$.each($({selector})), function(k,v) { attributes.push($(v).data("myAttribute")); });
This feels stupid. Is there simpler way to get the data for all the elements?
.map()
function returns a jQuery object but sometimes you could just need the underlying array. For that just add.get()
at the end of.map(...)
– Cliquish