CaribouCode
CaribouCode

Reputation: 14428

Why does getElementById().value not returning the element correctly?

I usually use jQuery but am starting to develop in pure javascript. I'm trying to create a variable for an element that I can use throughout the code but I can't seem to get it working. At the moment I'm trying:

var canvas = document.getElementById('canvas').value;

Then using that variable like:

canvas.style.backgroundPosition = '0 0';

Can someone please tell me what I'm doing wrong that is cause the variable to not be read or not declared properly?

Upvotes: 0

Views: 125

Answers (1)

adeneo
adeneo

Reputation: 318342

element.value returns the value as a string, not the element (and a canvas has no value).
For just the element remove the .value part

var canvas = document.getElementById('canvas');

canvas.style.backgroundPosition = '0 0';

Upvotes: 4

Related Questions