Micoxion Micoxion - 6 months ago 9
Javascript Question

How to get offset value of a large amount of span's with a common class

I currently have a large amount of span's all with a common class (as you probably guessed from the title). When I try:

$(".span-class").offset().top;


I am trying to check for a collision between one element and all of the spans without creating over 10 unique id's and
.offset
calls. But I only recieve the
.offset().top
value for the first element with the class in the HTML.

So is there a way to check the position on all these elements without 10 or so extra lines of code? Thanks in advance!

Answer
var spanArr = [];
$("span.span-class").each(function () {
   spanArr.push($(this).offset().top);        
});