function heightDetect() { $('.main_head').css('height', $(window).height()); }; heightDetect(); $(window).resize(function() { heightDetect(); });