In a scrip I try to get the width of an element like so:
var container = document.getElementById('content');
var cw = container.clientWidth;
But it gives me this error in the console:
Uncaught TypeError: Cannot read property 'clientWidth' of null
Executing the same statements in the console however, produces the desired value. How is that possible?
Screenshot of the console: