2

I want something to happen when I resize my browser window, but every thing on the page must be loaded first. This doesn't work, but you get the picture:

$(window).resize(function(){
    $(window).load(function(){
        // do stuff
    });
});

How can I make this work?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Robin Cox
  • 1,470
  • 2
  • 16
  • 31

2 Answers2

5

You need to attach the resize handler after the page has loaded, so reverse your event handlers:

$(window).load(function(){
    $(window).resize(function(){
        // do stuff
    });
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
2

I've recently had the same issue. Bind it both the load and resize event as below:

$(window).on('load resize', function () {
// your code
});

Hope this helps.

anti000gravity
  • 403
  • 3
  • 7