• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting context fillStyle from css property

 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such property as fillStyle.

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.

What are you actually trying to accomplish?
 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic