1

I am trying to get the width of my content box with the following comand:

var box = document.getElementById('player');
var boxSize = box.clientWidth;

It seems to return something. When I alert it it gives out a number. But it still throws the error:

Uncaught TypeError: Cannot read property 'clientWidth' of null

What is happening here?

Syam Pillai
  • 4,032
  • 2
  • 21
  • 38
Ipomea
  • 91
  • 2
  • 10

1 Answers1

1
var box = document.getElementById('player');
if(box){
  var boxSize = box.offsetWidth;
}
Syam Pillai
  • 4,032
  • 2
  • 21
  • 38