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 6380889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:33+00:00 2026-05-25T02:19:33+00:00

I have the need to test the offsetWidth and offsetHeight of an element. Presently,

  • 0

I have the need to test the offsetWidth and offsetHeight of an element. Presently, the element is attached and then the offsetWidth and Height are tested, after which the element is remove.

It looks like this:

var sizer = document.createElement('DIV');
sizer.innerHTML = element; //element is a string
document.body.appendChild(sizer);
if (sizer.offsetWidth > maxWidth) {
    sizer.style.width = maxWidth);
}
document.body.removeChild(sizer);

But that is VERY SLOW!

EDIT:
Complete code:

InfoBubble.prototype.getElementSize_ = function (element, opt_maxWidth, opt_maxHeight) {
var sizer = document.createElement('DIV');
sizer.style.display = 'inline';
sizer.style.position = 'absolute';
sizer.style.visibility = 'hidden';

 if (typeof element == 'string') {
    sizer.innerHTML = element;
 } else {
    sizer.appendChild(element.cloneNode(true));
 }

 document.body.appendChild(sizer);

 // If the width is bigger than the max width then set the width and size again
 if (opt_maxWidth && sizer.offsetWidth > opt_maxWidth) {
    sizer.style.width = this.px(opt_maxWidth);
    //size = new google.maps.Size(sizer.offsetWidth, sizer.offsetHeight);
 }

 // If the height is bigger than the max height then set the height and size
 // again
 if (opt_maxHeight && sizer.offsetHeight > opt_maxHeight) {
     sizer.style.height = this.px(opt_maxHeight);
     //size = new google.maps.Size(sizer.offsetWidth, sizer.offsetHeight);
 }
 var size = new google.maps.Size(sizer.offsetWidth, sizer.offsetHeight);

 document.body.removeChild(sizer);
 return size;
};
  • 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-05-25T02:19:34+00:00Added an answer on May 25, 2026 at 2:19 am

    The whole page may be being redrawn-
    Put the thing in an absolutly positioned, visibility hidden div element, it should be faster.

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

Sidebar

Related Questions

I have bunch of methods in which i need to test whether remote server
I have an application extension which I need to test. Part of the extension
I have an iPhone app which I need to test in an older version
I need to test the bandwidth I have on my USB RNDIS connection. I
I have a program that uses JAMA and need to test is a matrix
I have some code in my error handler I need to test against a
I only have one computer (running OS X), and need to test in both
I need to have a dynamic URL preferably from a Test Class. Can any
I have this JUnit test that I need help developing a Interface and Class
I have table to test score data that I need to pivot and I

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.