我如何获得所有兄弟姐妹的数据属性?
问题描述:
我有这个标记:我如何获得所有兄弟姐妹的数据属性?
<div class="photoList">
<img src="http://example.com/img1.jpg" data-zoom-url="http://example.com/img1.jpg">
<img src="http://example.com/img1.jpg" data-zoom-url="http://example.com/img1.jpg">
</div>
我想和数据-zoom网址的所有值的数组。我得到这个是接近:
console.log($j(this).parent().children().attr('data-zoom-url'))
的主要问题是,父母与孩子是那种不是很好,而我回来的东西不是一个数组,包含了各种东西。
答
使用.map
var dataValues = $j(this).parent().children().map(function() {
return $(this).attr('data-zoom-url')
}).get();