What is the best way to wire a single event to multiple elements?

36 views
Skip to first unread message

Alexander

unread,
Sep 3, 2012, 10:04:05 AM9/3/12
to nitro...@googlegroups.com
Hi. I have several dozen divs of the same css class. And I want to get an id (or value) of the single div when it is clicked. What is the best way to accompish this? Is it possible to wire an event to all these elements based on their css class and somehow be able to get individual id in a postback function? Something like

wf:wire(".folder", #event { type=click, postback={folder_click, <some_shortcut???>} })



Alexander

unread,
Sep 3, 2012, 12:16:41 PM9/3/12
to nitro...@googlegroups.com
It turns out #bind {...} does what i need. I had to use buttons instead of divs (panels) though, couse the latter have no means to assign a click postback to them.

Jesse Gumm

unread,
Sep 4, 2012, 8:11:51 PM9/4/12
to nitro...@googlegroups.com
Hi Alexander,

As you discovered, #bind{} does work well for that kind of action.
You can also do it with a list comprehension or lists:map, either way
works. I tend to use list comprehensions more frequently than
#bind{}, just as a personal preference.

Also, it's worth noting that elements can (and most do) have more than
one Nitrogen ID (a temporary ID and also a given ID if one is
specified in the code), so there's not a great way to get the ID of an
element.

Have a good one,

-Jesse
> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nitrogenweb/-/_bIbvzGi1AUJ.
>
> To post to this group, send email to nitro...@googlegroups.com.
> To unsubscribe from this group, send email to
> nitrogenweb...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nitrogenweb?hl=en.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Alexander

unread,
Sep 5, 2012, 5:41:00 AM9/5/12
to nitro...@googlegroups.com, gu...@sigma-star.com
Jesse, thanks a lot for the advice. I haven't thought of using list comprehensions - it's a much cleaner approach.
Reply all
Reply to author
Forward
0 new messages