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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:32:02+00:00 2026-05-23T06:32:02+00:00

With the code below, the alert doesn’t return the actual size of #main, it

  • 0

With the code below, the alert doesn’t return the actual size of #main, it always returns the value of #main’s css width with the % dropped. So in this case I get 95 in the alert. If I alert parent().width() I get 100.

The data returned from the .get() call is a ul that sometimes is wider than #main, and sometimes not. The width of the content doesn’t seem to have any bearing on what .width() returns.

So my question is, how do I get the true pixel width of #main?

CSS:

#container {
    width: 100%;
}

#main {
    width: 95%;
    overflow: hidden; 
}

HTML:

<div id="conatiner">
    <div id="main"></div>
</div>

Javascript/jQuery:

$.get('page.php', function(result) {
    $('#main').html(result);
});
alert($('#main').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-05-23T06:32:03+00:00Added an answer on May 23, 2026 at 6:32 am

    I ran into this same issue while trying to implement jquery.autogrow-textarea on textareas used for inline editing. The textareas were contained within div‘s that were not yet displayed (css display: none;). While debugging the .autogrow() javascript code, I discovered that jQuery’s .width() was returning the percentage value with the ‘%’ character removed as opposed to the calculated width in pixels (e.g. 100 for 100%, 80 for 80%).

    Here is the jsfiddle that illustrates this scenario: http://jsfiddle.net/leeives/ujE6s/

    To work around this, I changed my code to .autogrow() as soon as the textarea was displayed instead. The calls to .width() were then accurate.

    I’m not sure if you’re working with hidden content or not, but thought I’d write up my answer in case others stumbled upon this (like I did) while searching for an issue with jQuery’s .width().

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

Sidebar

Related Questions

i dont know what is actual problem in the below code, but it doesn't
Code below doesn't work on any browser. It's supposed to show an alert box.
The code below doesn't work in the same behavior. The sequence of click event
Please find my code below. My problem is that I the inner jQuery.get() doesn't
The code below has (at least) two problems: the Copy button doesn't update the
I use below code for accelerometer and it works on ipod 3g but doesn't
I have this code below. I don't know why inArray() doesn't output 0. Any
I have this function, see below: function checkStartPrice (){ if ($('#StartingPrice')[0].value.length == 0){ alert(The
Can someone tell me why the code below doesn't work. I think my theory
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {

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.