2
    console.log(document.getElementById("myCanvas").style.length);

I have this code in my program. It returns 0, despite the length of the canvas being 660. Does anyone know why?

Jeff Morse
  • 69
  • 3

2 Answers2

3

You can get the width and height through this.

var canvas = document.getElementById("myCanvas");
var width = canvas.width;
var height = canvas.height;
Severino Lorilla Jr.
  • 1,637
  • 4
  • 20
  • 33
2

In CSS there is no length attribute, there is just height or width. You can use this:

console.log(document.getElementById("myCanvas").style.height);
console.log(document.getElementById("myCanvas").style.width);
Wowsk
  • 3,637
  • 2
  • 18
  • 29
xuan hung Nguyen
  • 390
  • 3
  • 12