How to get an array of attribute value from elements in a jQuery object

前端 未结 3 908
温柔的废话
温柔的废话 2021-01-12 02:04

I use a custom attribute in elements with my own class. I\'m trying to return the value of custom attribute for all elements of the class.

I used jQuery to find th

3条回答
  •  萌比男神i
    2021-01-12 02:38

    Simple solution (ES6)

    Array.from(document.getElementsByClassName('tab_item')).map(item => item.getAttribute('foo'));
    

    Online demo (jsFiddle)

提交回复
热议问题