javascript - In JQuery, what's the best way to get a data attribute of a set of nodes into an array? -


in jquery, what's best way data attribute of set of nodes array?

i got syntax working:

var ids = $("a.some_class").map(function(index, item) {return item.getattribute('data-id');}); 

is there simpler syntax this?

thank you

there nothing easier map approach but, data method get things in cross browser way , return pure javascript array:

var data = $('a.some_class').map(function() {     return $(this).data('id'); }).get(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -