my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Setting context fillStyle from css property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Setting context fillStyle from css property" Watch "Setting context fillStyle from css property" New topic
Author

Setting context fillStyle from css property

Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
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

Joined: Jan 10, 2002
Posts: 61298
    
  66

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?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
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.





 
wood burning stoves
 
subject: Setting context fillStyle from css property