Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:03:47+00:00 2026-06-12T18:03:47+00:00

Possible Duplicate: Does using $this instead of $(this) provide a performance enhancement? So I

  • 0

Possible Duplicate:
Does using $this instead of $(this) provide a performance enhancement?

So I am creating a theater like photo gallery that takes up the entire screen, I change the sizes of the divs and Images depending on the window size. So to do this I have been using:

function setSizes()
{
var theaterHeight = $(".theater-wrapper").height();
var theaterWidth = $(".theater-wrapper").width();
}

$(window).on("resize", window, function() {
        setSizes();
    }); 

That’s basically what I am doing to select the elements in order to get the dimensions to set the heights and widths and such, however window resize does get a bit laggy, and I do end up having quite a few selectors and changing quite a few divs and images all in this one function, and also sometimes the initial call doesn’t work properly, or vice versa. So my question is would comibining the selectors result in better performance and such?

like:

var $theaterWrapper = $(".theater-wrapper");

var theaterHeight = $theaterWrapper.height();
var theaterWidth = $theaterWrapper.width();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:03:48+00:00Added an answer on June 12, 2026 at 6:03 pm

    Here’s a JSPerf that you can either use as is or modify to more closely match your specific case:

    http://jsperf.com/combined-jquery-selectors

    In my browser (Chrome on a Mac), your original version runs about 4% slower than your suggested optimization. On my iPhone using Safari, it’s about 6% slower. But on Firefox on my Mac, it’s a 14% difference.

    So it would appear that your proposed improvement is in fact better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Does using references instead of pointers, resolve memory leaks in C++? When
Possible Duplicate: What does :_* (colon underscore star) do in Scala? I’m using the
Possible Duplicate: How is floating point stored? When does it matter? Using the built-in
Possible Duplicate: How does this CSS triangle shape work? Please help me i need
Possible Duplicate: What does this C++ code mean? I'm trying to map a C
Possible Duplicate: Why does javascript replace only first instance when using replace? I have
Possible Duplicate: When does Endianness become a factor? reading this tuto on endianess, i
Possible Duplicate: What does () => mean in C#? Hi Everybody, This is my
Possible Duplicate: Where does Android emulator store SQLite database? I am using SQLite and
Possible Duplicate: Performance of try-catch in php While using try - catch blocks, even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.