Jeff Morse
Jeff Morse

Reputation: 69

Style.length and Style.width are not working

    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

Answers (2)

xuan hung Nguyen
xuan hung Nguyen

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

Severino Lorilla Jr.
Severino Lorilla Jr.

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

Related Questions