user2586329
user2586329

Reputation: 17

get several images' height from the page

I have images, which are taken from the database. I need to get the height each of them. If I do like that:

   $('.find_image_height').height();

I takes the first image height, how can I do that. (they array, of course, will help me)

Upvotes: 0

Views: 36

Answers (2)

Jonathan Crowe
Jonathan Crowe

Reputation: 5803

function getHeights() {
    var heights = [];
    $(".find_image_height").each(function(){
         heights.push($(this).height());
    });
    return heights;
}

Upvotes: 1

CodingIntrigue
CodingIntrigue

Reputation: 78525

You can use .map:

$(function() {
  var array = $(".find_image_height").map(function() {
     return $(this).height(); 
  }).get();
});

Here is a fiddle to demonstrate.

Upvotes: 0

Related Questions