jQuery's .width()
method doesn't seem to account for scroll bars. This is problematic for me, since I'd like to set the width of some children to equal the width of their parent. I used jQuery similar to the following:
$('#contentDiv').width($('#containerDiv').width())
In this example, #contentDiv
is the element I'd like to size, and I want to set it to have the width of #containerDiv
, which is its parent element. My problem is that this cuts off the side of #contentDiv
, as seen in this fiddle.
In my actual code, I have several elements that I'm sizing with jQuery, which all need to fit in the scrollable div, so just setting the css of #contentDiv
to 100% is not an option. What's the best way of dealing with scroll bar widths of divs in jQuery?