function setBgColorSize() { jQuery('.bgParent').each(function() { var parent = jQuery(this); parent.find('.bgColorSize').each(function() { jQuery(this).css('height', '100%'); }); var height = parent.outerHeight(); parent.find('.bgColorSize').each(function() { jQuery(this).css('height', height+'px'); }); }); } jQuery(function() { setBgColorSize(); jQuery(window).on('resize', function() { setBgColorSize(); }); });