I have several buttons each with a different background color. When the user clicks on one of these buttons I want to change the context fillStyle to the value of the button's background css property. It's not working how I thought it would.
In the code above the id of the button is passed to the function. Yet despite setting the background property in the css file to blue, when I print out the style property in an alert it displays nothing. The code below does work by changing the color of the button to green.
So why doesn't button.style.background print out the background property? Is it possible to set the context fillStyle to the css property this way?
And the property will only contain the values that are explicitly assigned to it. It will not reflect inherited property values or those applied via stylesheets.
Bear Bibeault wrote:There is no such property as fillStyle.
Sorry I think it's an attirbute, I'm still getting to grips with the Javascript terminology. I've found out the problem now. Apparently getComputedStyle is the way to go. Now it works as I thought it should.