Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 226
Krishna Avatar asked Mar 19 '23 03:03

Krishna


1 Answers

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

jQuery :

var width = $('.div2')[0]['clientWidth'];
$('.div1').css({'width':width+'px'});
like image 88
guramidev Avatar answered Mar 28 '23 05:03

guramidev