Reputation: 69
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?
Upvotes: 2
Views: 937
Reputation: 398
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);
Upvotes: 2
Reputation: 1637
You can get the width and height through this.
var canvas = document.getElementById("myCanvas");
var width = canvas.width;
var height = canvas.height;
Upvotes: 3