0

I am trying to target each div within another div of class show-grid

I am currently using this but it doesn't work. I am using https://github.com/liabru/jquery-match-height to get the height of the divs within each div of class show-grid to be the same height

div.show-grid:nth-child(1) div
div.show-grid:nth-child(2) div
...

<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
pee2pee
  • 3,619
  • 7
  • 52
  • 133

1 Answers1

0

I'm not entirely sure if this is what you need, but I've shown a way to use vanilla JS to select every second child of the 'show-grid' div (you can adapt to get the child you need). From there it is up to you to set the height as required:

var outerDivs = document.getElementsByClassName('show-grid');
var heightIWant = 100;

for ( var i = 0; i < outerDivs.length; i++ ) {

    // every 2nd child (as an example)
    if ( i % 2 == 0) {

      var innerDivs = outerDivs[i].getElementsByTagName('div');
      for ( var j = 0; j < innerDivs.length; j++ ) {
        innerDivs[j].style.height = heightIWant + 'px';
      }

  } 
}
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>
<div class="show-grid">
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
  <a href="">
    <div></div>
  </a>
</div>

}

}
Arnoux
  • 226
  • 2
  • 9