Hi, On Feb 25, 8:26 pm, Walter Lee Davis <wa...@wdstudio.com> wrote: > I have defined a new function on the Element namespace: > > //common function to switch tabs > Element.addMethods({ > setTab: function(elm, evt){ > //hide all the content > bodies.invoke('hide'); > tabs.invoke('removeClassName','active'); > elm.addClassName('active').bodies.invoke('show'); > } > }) > > It works perfectly when it's passed from an element > > $('sometab').setTab(); > > But if I want to register a click handler on all the tabs: > > tabs.invoke('observe','click', setTab); > > I get an error: > > TypeError: 'undefined' is not a function (evaluating 'handler.call(element, > event)') > > ...from Prototype 1.7 in Safari 5.1.2. > > Is there a way to write this so it will work in both contexts, or do I need > to add an explicit event handler form of the method somewhere else? > > If I write the handler like this: > > tabs.invoke('observe','click', function(evt){ this.setTab(); } ); > > ...then it works perfectly, but I'm confused why it's not working in the > other syntax. I could swear I've used that same construction earlier and had > it work just fine. > > Thanks in advance, > > Walter
Here's how you would hook that up: tabs.invoke('observe','click', Element.Methods.setTab.methodize() ); Live example: http://jsbin.com/opitis Explanation: * `Element.Methods` contains all of the methods that will be applied to elements when augmenting them (including ones you add) http://api.prototypejs.org/dom/Element/Methods/ * `methodize` is what Prototype uses to turn Element.setTab("foo") into $("foo").setTab(); http://api.prototypejs.org/language/Function/prototype/methodize/ Hope this helps - happy coding! -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.