我想基於元素的頂部位置。要改變自定義屬性更改自定義屬性基於頂部位置
<div class="wrapper">
<div class="class" customAttribute="2" top="600"></div>
<div class="class" customAttribute="1" top="500"></div>
<div class="class" customAttribute="4" top="200"></div>
<div class="class" customAttribute="3" top="400"></div>
<div class="class" customAttribute="6" top="300"></div>
<div class="class" customAttribute="5" top="100"></div>
</div>
for (var i = 0; i < 6; i++) {
var firstChild = // gets the customAttribute of the child with the lowest position top value;
$('.wrapper:nth-child(firstchild)').attr('customAttribute', i);
}
此外,還有將在年底超過6點的div所以它需要是程序性的。謝謝。
你爲什麼不使用真正的自定義數據屬性? 'data-' – j08691
這不是實際的屬性,它只是一個沒有數據的例子。 – pauld
根據'top'對它進行排序,然後設置'customAttribute',你有什麼特別的嘗試? – beautifulcoder