Get inner width of an element
HTML
<div id="test">If a scrollbar appears, the width isn't valid</div>
CSS
div {
background-color: #5555FF;
color: white;
width: 100%;
}
JavaScript
function getInnerWidth(elem) {
return parseFloat(window.getComputedStyle(elem).width);
}
var test = document.getElementById("test");
// replace % value with pixels
test.style.width = getInnerWidth(test) + "px";