2015-03-13 53 views
0

我有這個標記:我如何獲得所有兄弟姐妹的數據屬性?

<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')) 

的主要問題是,父母與孩子是那種不是很好,而我回來的東西不是一個數組,包含了各種東西。

回答

1

使用.map

var dataValues = $j(this).parent().children().map(function() { 
    return $(this).attr('data-zoom-url') 
}).get();