How about this (untested): var stickyFooter = function() { var height = $(document).height(); var height = height - 341; $('#footer').css('margin-top', height); }
$(document).ready( stickyFooter(); ); $(window).resize( stickyFooter() ); HTH, Carl Chris P wrote: > I wanted a script that would make a sticky footer, and it worked > perfectly with this (where 341 is the elements to offset). > > var height = $(document).height(); > var height = height - 341; > $('#footer').css('margin-top', height); > > Then I want this code to re-run on browser resize. I also want to > refactor the code above to use a second time. The problem is that (1) > it doesn't re-run on browser resize and (2) I don't want to duplicate > code. How can I refactor? > > var height = $(document).height(); > var height = height - 341; > $('#footer').css('margin-top', height); > > $(window).resize(function(){ > var height = $(document).height(); > var height = height - 341; > $('#footer').css('margin-top', height); > }); > > >