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');
});
2
  • 2
    stackoverflow.com/questions/2534089/… Commented May 1, 2015 at 1:15
  • 2
    @JonathanAnctil - except in this case, the ready event is on the document object and the resize event is on the window object. Commented May 1, 2015 at 1:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.