I hav an array:
var positions = ["north-america",{"top":512,"left":0},"central-america", {"top":512,"left":85},"united-kingdom",{"top":512,"left":180}];
that I need to itterate over and create a label eg
<div>North America</div>
then position it using the object in the array
<div style="top:512; left:0">North America</div>
I keep getting lost in the iterations using this jQuery.
$.each(positions, function (i, object) {
$('<div/>', {
class: 'map-label dragee ' + object,
region: object
}).appendTo('#front-end-map');
$('#labels').append('<h3>' + object + '</h3>');
$('#labels').append('<span><a href="#">Read More</a></span>').drags();
});
Any help much appreciated.
when I modify to this:
for (var i = 0; i < positions.length; i += 2) {
var name = positions[i];
var pos = positions[i + 1];
$('<div/>', {
class: 'map-label ' + name,
region: name
}).css({
top: pos.top + 'px,',
left: pos.left + 'px'
}).appendTo('#front-end-map');
$('.map-label').append('<h3>' + name + '</h3>');
$('.map-label').append('<span><a href="#">Read More</a></span>').drags();
}
its almost there, but I get no top position in the style attribute, and it still itterates in error, I get 3 elements then 2 then 1??