0

I can get an HTML element from my clojurescript page in the REPL:

cljs.user=> (.-innerHTML (.getElementById js/document "app"))
"This is clojure"

But how do i change this element to for example: "This is awesome clojure"

David
  • 2,926
  • 1
  • 27
  • 61
  • 3
    Does this answer your question? [How can I use Clojurescript to interact with the html DOM?](https://stackoverflow.com/questions/45228474/how-can-i-use-clojurescript-to-interact-with-the-html-dom) – cfrick Jul 13 '21 at 11:48

1 Answers1

1

You can mutate this element like so...

(set! (.-innerHTML (.getElementById js/document "app")) "This is awesome ClojureScript")

And please be aware that you could also say...

(set! (.. js/document (getElementById "app") -innerHTML) "This is awesome ClojureScript")

...in case that is more attractive to you. Or you could say...

(->> "This is awesome ClojureScript" (set! (.. js/document (getElementById "app") -innerHTML)))

...or...

(let [app-element (js/document.getElementById "app")] (set! (.-innerHTML app-element) "This is awesome ClojureScript"))

Blessings, Raphael

Dharman
  • 30,962
  • 25
  • 85
  • 135