plumatic / dommy

A tiny ClojureScript DOM manipulation and event library
759 stars 73 forks source link

Click Events do not work #66

Closed alice157 closed 10 years ago

alice157 commented 10 years ago

I just started using dommy the other day, and the first thing I tried to do was use it to detect when a button was pressed and append text somewhere on the page. The problem is, dommy doesn't appear to listen for click events, or at least call the handler for it. My site.cljs looks like this: (ns site (:require [dommy.utils :as utils] [dommy.core :as dommy]) (:use-macros [dommy.macros :only [node sel sel1]])) (defn test [](dommy/append! %28sel1 :#topbar%29 %28node [:p "test"]))) (dommy/listen! (sel1 :#Home) :click test)

And my html file looks like this: http://pastebin.com/7718eTGV When I click on the home button, the word test should be added to the

tag, but it is not. However, calling site.test(); from the javascript console makes a new
with the same id as the original one and adds the word test to that.

Is this a bug, or simply user error?

cpetzold commented 10 years ago

It looks like you're missing the arg vector in your defn, should be:

(defn test [e] (node [:p "test"])))

Also, node only creates the node. If you want to add it to the dom, you'll need to use something like dommy/append!.