tags:

views:

56

answers:

1

Hi this is an example of my code. I want to get the margin-top from all the "divs" contained in the div appointmentContainer.

<div class="appointmentContainer">
    <div style="width: 940px; z-index: 8; background-color: yellow; position: absolute; margin-top: 0px;" class="a_162">
        <a id="a_162" class="appointments">414<br/></a>
    </div>
    <div style="width: 940px; z-index: 8; background-color: yellow; position: absolute; margin-top: 15px;" class="a_164">
        <a id="a_164" class="appointments">aaaa<br/></a>
    </div>
</div>

so I have something like ths and I want to find the margin-top's in both of the above divs.

So so far I have this

$('#a_162').parents('div:eq(0)').children('a');

So thats what I have so far. I want to find all the anchor tags from that parent div what is appointmentcontainer and get a list of all the margin-tops.

So I would like a list like

margin-top : 0
margin-top: 15

or

0
15
A: 

Your question is a bit unclear, but this will get all the margin-tops of divs inside .appointmentContainer which has a link with ID of #a_162:

var margin_tops = [];
$('#a_162').closest('.appointmentContainer').find('div').each(function() {
    margin_tops.push($(this).css('margin-top'));
});

alert(margin_tops.join("\n"));

What I don't understand is why you tried to select the a elements as the margin-top was applied to the div element?

Tatu Ulmanen
sorry ya no 'a' I was writing it in a real rush. I will try what you got out in a while. What is .push and join though? Is it also better to do closest then parents?
chobo2
`push` and `join` are array methods (http://www.w3schools.com/jsref/jsref_obj_array.asp), and using `closest` is simpler than `parent`. Note that you shouldn't use `parents` if you want to select only one item, by default, `parents` will select all the elements up to the `html` element.
Tatu Ulmanen