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,427
  • 2
  • 25
  • 40
Ipomea
  • 101
  • 2
  • 12

1 Answers1

1
var box = document.getElementById('player');
if(box){
  var boxSize = box.offsetWidth;
}
Syam Pillai
  • 4,427
  • 2
  • 25
  • 40