hoplon

itaied 2023-07-24T16:07:22.077919Z

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?

2023-07-24T17:13:10.991079Z

for the jquery impl., you can use a special :css attribute like such: https://github.com/hoplon/demos/blob/326cdb6299ebe6e1d6ce504d61a88e84e70d968a/demos-homepage/src/demo/homepage.cljs#L21C1-L22

2023-07-24T17:13:25.820379Z

the attribute value can be a cell that you can modify

itaied 2023-07-24T17:39:06.603419Z

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 % "..."))

2023-07-24T17:40:36.998869Z

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%")

🙌 1