Q:

jquery each loop to work out correct vertical margins

i am trying to make jquery calculate the height of the parent then the child then calculate the correct margins to apply to the children.
The calculations work fine, just that it is not looping for each child of the loop;
var navHeight = $('#nav').height();
var navImgHeight = $('#nav li img').height();

$('#nav li img').each(function(){

    $(this).css({ "margin-top" : ((navHeight - navImgHeight) / 2) });

});

A:

It is because in your example you are defining navImgHeight once, when you need to define it for each image (see the for each?):
var navHeight = $('#nav').height();

$('#nav li img').each(function(){
    var navImgHeight = $(this).height();
    $(this).css({ "margin-top" : ((navHeight - navImgHeight) / 2) });
});

