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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:46:28+00:00 2026-06-13T11:46:28+00:00

I want width of a div element which is specified by developer. Means if

  • 0

I want width of a div element which is specified by developer.
Means if you write $('body').width(), it will provide you width in px , whether you have specified it or not.

I need width of div specified in CSS/JavaScript but not which is calculated by jQuery (which was not actually specified but was inherited).

If not width is specified then I need to know.

  • 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-13T11:46:29+00:00Added an answer on June 13, 2026 at 11:46 am

    The code below will loop through all stylesheets as well as the matching element’s style property. This function will return an array of widths.

    function getCSSWidths( id ) {
    
        var stylesheets = document.styleSheets;
        var widths = [];
        var styleWidth;
    
        // loop through each stylesheet
        $.each( stylesheets, function( i, sheet ) {
    
            var len = ( sheet.rules.length || sheet.cssRules.length );
            var rules = sheet.rules || sheet.cssRules;
    
            // loop through rules
            for (var i=0; i < len; i++) {
    
                var rule = rules[i];
    
                // if width is specified in css add to widths array
                if (rule.selectorText.toLowerCase() == "#" + id.toLowerCase() ) {
                    widths.push( rule.style.getPropertyValue("width"));
                }
            }
        });
    
        var el = document.getElementById( id );
    
        // get width specified in the html style attribute
        if( el && el.style && el.style.width ) {
            widths.push( el.style.width );
        }
    
        return widths;
    }
    
    getCSSWidths( "test" );
    

    Fiddle here

    There is one issue that I can see though as multiple selectors can be specified in the selectorText i.e.

    #id1, #id2, .class1 {
        // properties
    }
    

    In these cases the id passed in as an argument will not match the selectorText property. Maybe someone can come up with a regex expression that will match the specified id 🙂

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

Sidebar

Related Questions

I have a <div> element which contains text and I want to align the
I want to position a div element centered in a page with width about
I have a div with width 600 px. I want to pull the images
I want to fetch div element from other website . on which iam having
On my page, I have multiple div with specified class which have 2 span
I have an html div element, which contains lot of HTML-5 data- attributes to
When reading width of DIV section, the result comes in %. But, I want
I want to change all child divs(parent div id=product_list) with a width of 41%
What I want: <div style=overflow:scroll;width:100%;height:50%;> &nbsp; <div style=height:500px;width:400px;border:solid 3px red;> </div> </div> <div style=overflow:scroll;width:100%;HEIGHT:50%;>
It doesn't stay where I want it, look at this: <div style=float: left; width:

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.