开发者

jQuery selector for the child of a parent's previous sibling

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';
  }})
})


Use:

$(this).parent().prev().find('.goal').width()

This also works:

$(this).parents('.stats').find('.label > .goal').width()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜