166
rated 0 times
[
171]
[
5]
/ answers: 1 / hits: 12581
/ 11 Years ago, thu, january 23, 2014, 12:00:00
this is what I've got and been struggeling for hours. if I alert(i)
in the each loop it gives me 1,2,3...
but if I want to use as as key for a multidimensional array it is like a string i
$(document).ready(function(){
var positions=[];
$( .box ).each(function(i) {
//alert(i);
var elPositions = {};
elPositions.i = $(this).offset().top;
positions.push(elPositions);
//$elPosArray[i] = $(this).offset().top;
//$(this).html('outer height--> ' + $(this).outerHeight(true));
});
console.log(positions);
//console.log(el);
});
There are Questions and answers to this topic but none of them helped me to get this to work.
I would like to get an array or obj looking something like:
positions[0]['offset'] = '120';
positions[0]['height'] = '300';
positions[1]['offset'] = '420';
positions[1]['height'] = '180';
positions[2]['offset'] = '600';
positions[2]['height'] = '100';
positions[3]['offset'] = '700';
positions[3]['height'] = '300';
Here is a fiddle with the html http://jsfiddle.net/Z9WrG/
More From » jquery