Fork me on GitHub
#hoplon
<
2023-07-24
>
itaied16:07:22

Hey all, how can I add style to an element after its creation? I have some a place in my project that creates (h/div {:style "min-width: 40px; min-height:80px;background-color:#ebffca;"} "a"), and then in another place I want to enrich it, like (assoc elem :style "width:100%"). How can I do it?

alandipert17:07:25

the attribute value can be a cell that you can modify

itaied17:07:06

do i need to wrap my element in a div? I prefer appending \ overriding the current style of the element without adding a new one. Something like that:

(def a (h/div {:style "..."}))
(update a :style #(str % "..."))

alandipert17:07:36

oh, i just realized that h/div is a regular HTML element, so you can mutate the style on it like any HTML thing.. like (set! (.-style elem) "width:100%")

🙌 2