Reputation:
For each stat block like the following:
<div class="stats">
<div class="label">
<span class="goal">10 YEARS OF SOMETHING GOOD</span>
</div>
<div class="stat">
<div class="tri"></div>
</div>
</div>
I want to set the marginRight of tri
to half the width of the previous goal
. Which jQuery selector would I use to grab the previous 'goal' relative to each tri
?
Something like..
$(function(){
$('.tri').css({marginRight: function() {
return Math.floor($(this).something('.goal').width() / 2) + 'px';
}})
})
Upvotes: 3
Views: 6741
Reputation: 2339
Use:
$(this).parent().prev().find('.goal').width()
This also works:
$(this).parents('.stats').find('.label > .goal').width()
Upvotes: 4