I want to make my all div height equal to the first child of the inside div
here I have three div p , p2 , p3
which is inside of another div called(class) r
, I want to make my p2 , p3
same height to p
.
HTML
<div>
<div class="r">
<div class="p">fgdsgs</div>
<div class="p2">sdgdfg</div>
<div class="p3">sdgdfg</div>
</div>
</div>
CSS
.p,.p2,.p3{
display:inline-block;
width:80px;
}
.p{
height:50px;
}
JS
var firstChild = document.querySelector(".r:first-child");
var descendant = firstChild.querySelectorAll(".p, .p2,.p3");
[].forEach.call(descendant, function(itm){
itm.style.backgroundColor = "green";
var ch = document.getElementsByClassName("p").clientHeight;
for(var i = 0 ;i < ch.length; i++ ){
itm.style.height = ch[i] + "px";
}
});
Demo - https://jsfiddle.net/104sn7mu/13/
Edit 1
loops added