Now I have working on window load code, but can't make it work with window resize (height values will increase if I repeat the same function for resize event). Array is to show initial values after onload completed.
var arr = [];
window.onload = function() {
var newsBlocks = document.getElementsByClassName('news');
for (var i = 0; i < newsBlocks.length; i++) {
var newsBlock = newsBlocks[i];
var left = newsBlock.getElementsByTagName('article')[0];
var right = newsBlock.getElementsByTagName('article')[1];
var height = Math.max(left.offsetHeight, right.offsetHeight);
left.style.height = right.style.height = height.toString() + 'px';
arr.push(left.style.height);
console.log(arr);
}
};
Here is html:
<div class="main">
<section class="news">
<article>
<a href="#" class="news-image"><img src="images/t.png"></a>
<h2><a href="#">Heading</a></h2>
<a href="#" class="description">test text</a>
</article>
<article>
<a href="#" class="news-image"><img src="images/t.png"></a>
<h2><a href="#">Heading</a></h2>
<a href="#" class="description">a lot of test text here</a>
</article>
</div>
Pure JavaScript solution is appreciated. Thanks in advance for a help!