Krishna
Krishna

Reputation: 1362

Get the Div width without the scroll Bar width

I am having a issue here. There are two div's here "div1" and "div2". Here I want to adjust the "div1" width according to the "div2" width. My requirement is The width of the scrollBar should not be included for the "div1" i.e i should set the height of the "div1" excluding the width of the scrollBar in "div2". I want a jquery function to find the width and to reduce the width of "div1".. Sample requirement is shown below

html

<div class="div1"></div>
<div class="div2">HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello</div>

css

.div1
{
    width:100px;
    height:100px;
    border:1px solid black;
}
.div2
{
    width:100px;
    height:300px;
    border:1px solid black;
    overflow:auto;
    word-break:break-all;
}

enter image description here

The Fiddle Demo is here

Fiddle

Upvotes: 4

Views: 6852

Answers (1)

guramidev
guramidev

Reputation: 2238

See this: http://jsfiddle.net/d34Fk/5/

jQuery :

var width = $('.div2')[0]['clientWidth'];
$('.div1').css({'width':width+'px'});

Upvotes: 7

Related Questions