Fork me on GitHub

Hi, I've just started learning Clojurescript but I'm stuck on something pretty basic. I have some content in my web page that I have set to hidden using CSS. I want to make it visible based on a user click. I could use a library like Domina for that (I think) but if I wanted to do that using just Cljs how should I go about it? I'm a bit confused with the Cljs/JS interop. I can get the element using (.getElementById js/document "my-element"). And then what? How can I access the style and the display property declared in my CSS?


Btw I got what I wanted from Domina with a single call to set-styles!. I was thinking I will learn more about how Clojurescript actually works by doing it by hand but maybe its a silly idea simple_smile


Doing (sort-by val > (frequencies [5 5 1])) gives me ([5 2] [1 1]) but what is a way to get [5 2]?


oh wow that actually did work.


@edwthomas: there are several ways to access JS properties


I like the .- notation


So you could e.g. do (.-style (.getElementById js/document "my-element"))


And use set! to change the value


@trancehime: How in hte world did you get the bot to do that?


@rantingbob: there's a slash command. If you type /clj (+1 2) it will evaluate it.


@rantingbob: I didn't actually do that, someone else did - you can see who requested the eval in the ;; comment


What's the Clojure way when it comes to functions receiving invalid arguments? Return nil? Throw an exception? The functions are part of the API of my core library.


clojure.core functions throw IllegalArgumentExceptions, if some other exception doesn’t bubble up first (e.g., ClassCastException)


@polymeris: Thanks! I’ll try that out.


@polymeris: This worked: (set! (.-display (.-style (.getElementById js/document "my-element"))) "block"). Like with all the minor roadblocks I've experienced in Clojure, once I get some guidance and see something work in the repl, it all makes sense. Thanks!

Drew Verlee22:12:35

What's a top level function (defn) , vs just one created with fn?


The former creates a var that resolves to the fn