On Dec 16, 2006, at 6:26 PM, José de Paula Eufrásio Júnior wrote:
> On 12/16/06, Christopher Arndt <[EMAIL PROTECTED]> wrote:
>> You need to give elements, to which you want to attach a handler,
>> an ID
>> or a CLASS attribute and then use MochiKit's 'getElement' or
>> 'getElementByTagAndClassName' functions to locate the element(s) and
>> attach the handler with 'connect'.
>
> Did that. A simple connect is working, but now I am thinking that a
> lot of things will be harder now, like, I have a list of links that
> can be clicked, this list is dynamic. Using 'onclick' I could just put
> the functions and parameters on the command line, with the 'connect'
> stuff it seems not possible, I have a 'generic' function to connect
> all the events of a given type but not much how to get information...
It's even easier :) To connect a list of links you could add each of
the a CSS class "foo" and then attach an event handler for each of
them in a straightforward way:
function eventHandler(event) {
var link = event.src();
// do something useful, link is the link that was clicked...
}
function addHandlers() {
var elems = MochiKit.DOM.getElementsByTagAndClassName('a','foo');
MochiKit.Base.map(function (link) {
MochiKit.Signal.connect(link, 'onclick', eventHandler);
}, elems);
}
HTH,
Alberto
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---