Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get full width of an element when it has absolutely positioned child elements inside it

JS Fiddle: http://jsfiddle.net/meYnS/3/

Lets say I have an element .outer with 100px width and position:relative;. It has an inner element which has position:absolute; and left:95px;. I.e. the child element exceeds the width of the parent element.

Now, in JQUery, if I try to get the width of the parent using $('.outer').outerWidth(); it return 100.

But how can I get the full width of the outer element (which is obviously greater than 100, because of the absolutely positioned child element)?

Is there a built-in way or do I have to do a manual calculation (i.e. adding each child width to parent width to figure out the full width)?

like image 328
Veera Avatar asked Jan 16 '23 18:01

Veera


1 Answers

You can use the properties scrollWidth, scrollHeight.

If you are using jQuery,

$('.outer').get(0).scrollWidth
like image 175
Diode Avatar answered Jan 18 '23 07:01

Diode