JQuery selector for child of parent of previous brother

For each stat block, as shown below:

<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 marginRight trito half the width of the previous one goal. What jQuery selector would I use to grab the previous “target” relative to each tri?

Sort of..

$(function(){
  $('.tri').css({marginRight: function() {
    return Math.floor($(this).something('.goal').width() / 2) + 'px';
  }})
})
+3
source share
1 answer

Using:

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

This also works:

$(this).parents('.stats').find('.label > .goal').width()
+5
source

Source: https://habr.com/ru/post/1796573/


All Articles