最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Jquery, know width and height of a div with scroll bar - Stack Overflow

matteradmin20PV0评论

I want have width and height of a full div with scroll using JQuery, but i can only have size of visible content and not size of visible + hidden content of scroll bar.

Anyone knows anyway to have this values (width and height)?

<div id="area" class="divLeftCem area">
    <div id="panelArea" class="areaBackground"
        style="width: 1004px; height: 613px; background: #FFFFFF url('Images/background.png') repeat;">
    </div>
</div>

.area
{
    margin-left: 10px;
    width: 1004px;
    height: 613px;
    border: 1px solid #AFAFAF;
    overflow: auto;
    position: absolute;
    top: 145px;
}

PS: Sorry about bad english.

I want have width and height of a full div with scroll using JQuery, but i can only have size of visible content and not size of visible + hidden content of scroll bar.

Anyone knows anyway to have this values (width and height)?

<div id="area" class="divLeftCem area">
    <div id="panelArea" class="areaBackground"
        style="width: 1004px; height: 613px; background: #FFFFFF url('Images/background.png') repeat;">
    </div>
</div>

.area
{
    margin-left: 10px;
    width: 1004px;
    height: 613px;
    border: 1px solid #AFAFAF;
    overflow: auto;
    position: absolute;
    top: 145px;
}

PS: Sorry about bad english.

Share Improve this question edited May 21, 2012 at 15:15 Quaquil asked May 21, 2012 at 14:49 QuaquilQuaquil 1111 gold badge1 silver badge5 bronze badges 3
  • I think jQuery gives you the actual size of the div. Could you put some code examples? – davids Commented May 21, 2012 at 15:00
  • Exact, only give me the visible size of the div. – Quaquil Commented May 21, 2012 at 15:09
  • I mean, it should give you the size of the complete div. Please, edit your question and add some code examples – davids Commented May 21, 2012 at 15:14
Add a comment  | 

1 Answer 1

Reset to default 15

Get the element's .scrollHeight:

$(".el").get(0).scrollHeight;

​ It goes without saying you could use .scrollWidth for the x-axis as well.

Fiddle: http://jsfiddle.net/spN6n/

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far