Reputation: 1174
I have a dom element (div) with some css properties like background-color, padding etc., which I'm trying to access like so:
(prn (-> my-dom-element .-style .-background-color))
But this is printing nil. However, just doing:
(prn (-> my-dom-element .-style))
does print the expected #object[CSSStyleDeclaration [object CSSStyleDeclaration]]
What am I doing wrong?
-- Edit --
I've tried (prn (gs/getStyle my-dom-element "background-color"))
with (:require [goog.style :as gs])
, but that prints the empty string. How do I fix this?
Upvotes: 1
Views: 172
Reputation: 4376
background-color
is not a valid JS property name since it would literally be background - color
(MINUS). The compiler always munges that to background_color
to make it valid JS, which of course is no longer a valid CSS name.
However since JS has the same issue the style property names use camelCase notation so the proper name would be backgroundColor
.
You can use (gs/getStyle my-dom-element "background-color")
with (:require [goog.style :as gs])
in your ns
which will take care of converting the property name.
Upvotes: 1