clojurescript Using JavaScript Interop


Example

(ns so-doc.events)

(enable-console-print!)

(defn click-event []
  (println "Button clicked"))

(defn load-event []
  (println "Page loaded!")
  (.addEventListener (.getElementById js/document "btn") "click" click-event false))

(.addEventListener js/window "load" load-event false)

Like normal Javascript, this method requires browser specific handling. This will not work in Internet Explorer for instance.

Unlike Google Closure, JavaScript easily supports page-load events.