0

Is it possible to have multiple events in jQuery, like this?

$(window).resize(function () {
    $('#page-wrapper').css('height', (window.innerHeight - 51) + 'px');
});

Now it's just resize() but is it possible to make it so that it is on both resize and ready?

$(window).resize.ready(function () {
    $('#page-wrapper').css('height', (window.innerHeight - 51) + 'px');
});
vitaut
  • 49,672
  • 25
  • 199
  • 336
  • 2
    http://stackoverflow.com/questions/2534089/jquery-multiple-events-to-trigger-the-same-function – Jonathan Anctil May 01 '15 at 01:15
  • 2
    @JonathanAnctil - except in this case, the `ready` event is on the `document` object and the `resize` event is on the `window` object. – jfriend00 May 01 '15 at 01:15

1 Answers1

1

Usually, this is done like this by just triggering a resize event when the document is ready which will then call your normal resize handler:

$(window).resize(function () {
    $('#page-wrapper').css('height', (window.innerHeight - 51) + 'px');
});

$(document).ready(function() {
    // trigger a resize event when the document is ready
    $(window).resize();
});

See the third form of .resize() in the jQuery doc. If it is called without any arguments, then it triggers the resize event so existing event handlers are called.

jfriend00
  • 683,504
  • 96
  • 985
  • 979