-2

As the title asks... Is there a way to have this update with browser resize rather than refresh alone?

$(document).ready(function() {
    $("#footer-container").css({'height':($("#footer").height()+'px')});
});
Joe
  • 15,205
  • 8
  • 49
  • 56
Tom
  • 314
  • 2
  • 14
  • 3
    possible duplicate of [Cross-browser window resize event - JavaScript / jQuery](http://stackoverflow.com/questions/599288/cross-browser-window-resize-event-javascript-jquery) or [JQuery: Detecting a Browser Resize](http://stackoverflow.com/questions/2031872/jquery-detecting-a-browser-resize) – Joe Jun 12 '13 at 20:37
  • 1
    Also, if you search your _exact_ title in google this comes up: [Make an equal height function resizeable on window resize](http://stackoverflow.com/questions/12903181/make-an-equal-height-function-resizeable-on-window-resize) – Joe Jun 12 '13 at 20:42
  • 2
    I don't understand why people even bother answering questions like this... – jahroy Jun 12 '13 at 20:47
  • I did a search on here and nothing came up that made sense to me. Sorry for duplicate :-/ – Tom Jun 13 '13 at 14:58

2 Answers2

1

use .resize()

$(window).resize(function(){
   $("#footer-container").css({'height':($("#footer").height()+'px')});
});
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
  • This worked for me thank you. I want it to do the resize before window resize as well so I wrote it like this. `$( document ).ready(function() { $("#footer-container").css({'height':($("#footer").height()+'px')}); $(window).resize(function(){ $("#footer-container").css({'height':($("#footer").height()+'px')}); }); });` – Tom Jun 13 '13 at 15:01
  • You can just trigger resize like this - `$(window).resize(function(){ $("#footer-container").css({'height':($("#footer").height()+'px')}); }).resize();` – Adil Shaikh Jun 13 '13 at 15:02
  • Oh that's so much cleaner! I gotta say I'm not understanding how that is working though. – Tom Jun 13 '13 at 15:08
  • @Tom You can follow the api `--->` http://api.jquery.com/trigger/ – Adil Shaikh Jun 13 '13 at 15:09
  • Ah I see, it applies it normally and when you append the ".resize();" to it, it also runs it for that action as well. Thanks again – Tom Jun 13 '13 at 15:19
0

Attach an event handler to the window object for the resize event.

$(window).on('resize', function() {} );
Brad M
  • 7,857
  • 1
  • 23
  • 40