Reputation: 729
Is there a way that I can get the width of one element .container
for example and apply it to another .item
for example?
My layout is responsive, hence why I can't just give .item
a fixed width value.
Upvotes: 4
Views: 3431
Reputation: 960
To get the width without jquery, just simple javascript line of code:
var width = document.getElementById('foo').offsetWidth;
Note: this will get the width of the element + the border width as well
Ex. html:
<div class="foo"></div>
style:
.foo {
width: 100px;
border: 1px solid #CCC;
}
in this case the width will be:
100px width + 1px right border + 1px left border = 102px
Hope that help.
Upvotes: -1
Reputation: 44740
Like this -
$('.item').width($('.container').width());
Demo ---->
http://jsfiddle.net/xQ7hh/
Upvotes: 12