I am having trouble getting the width of an element defined in CSS. I figured out how to get the CSS rules using Javascript, but I can't access the width. Menu is fixed width that I defined in CSS using em.
I am trying to change the width of the div1 based on the browser window minus the fixed menu width.
Note: I already tried using style.width
, but it returns a blank line in the console.
jsfiddle: http://jsfiddle.net/kj6pQ/
var div1 = document.createElement('div'),
css = getMatchedCSSRules(document.getElementById('menu'));
console.log(css); //works but dont' konw how to access width
div1.style.width = window.innerWidth - <!-- menu width -->;