0

html file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
  </head>
  <body>
    <h1 id="app">This is clojure</h1>
  <button "test" onclick="hi()">hello</button>
    <script src="out/main.js" type="text/javascript"></script>
  </body>
</html>

hello world file: (ns hello-world.core)

(println "Hello world!")

(def hi []
(println "test")

  )

Should "hi" not get invoked in this clojure script project?

1 Answer 1

3

No. Every reference in CLJS is namespaced. If anything it would be hello_world.core.hi() instead of just hi(). You should however never hook up events this way.

Instead change your HTML to <button id="test">hello</button> and then somewhere in your CLJS call this to add the actual event handler.

(let [el (js/document.getElementById "test")]
  (.addEventListener el "click"
    (fn [e]
      (println "test")))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.