複数の列があるWebサイトがあります。各列には0〜10行を含めることができます。行にはさまざまな要素が含まれていますが、常にすべての行の同じx位置にある特定の要素があります。
3行を超える列にあるすべての行を識別したいと思います。したがって、これらの「特別な」要素をすべてループして、同じx位置を持つ要素が3つ以上ある場合は、特定のクラスを追加したいと思います。
let xPositions = []
let specialElements = $("span[aria-label='specific text']")
specialElements.each(function() {
xPositions.push(this.x) // obviously this.x does not work. How can I get x?
})
specialElements.each(function() {
let count = xPositions.reduce((cnt, val) => val == this.x ? cnt + 1 : cnt)
if(count > 3){
this.addClass('highlight')
}
})
私はナイーブかもしれないことを知っていますが、xを親コンテナに対する相対的な位置として理解しています。おそらく、jqueryの位置関数を使用してください。
elPosition = $(this).position();
xPositions.push(elPosition.left);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加