开发者

how to get the margin-top with jquery when inline

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" 开发者_如何学Cclass="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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜