• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Setting context fillStyle from css property

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic