CopyEvents still rebinds the events, just hides the implementation for you. You could try to just replace the text inside the anchor tags instead, that way you never actually clear the anchor tag itself.
you could also go in the direction of each anchor tag calling a common function on click that decides on the fly what to do given the characteristics of the anchor tag that was clicked, thereby never actually attaching all the specific behaviors to each anchor. though i don't know how you keep track if a click is even or odd then. btw, if the two function that look the same are on the same page, why not define the function and call them: ToggleFunctions.onClickEven = function(){ > var el = $(this).parent(); > $(el).next().fadeOut("fast"); > $(this).text('Show'); > return false; > }; $("a.toggleBelowLoadedContent").toggle(ToggleFunctions.onClickEven,...) ----- Original Message ---- From: Brandon Aaron <[EMAIL PROTECTED]> To: jquery-en@googlegroups.com Sent: Tuesday, April 10, 2007 5:37:03 AM Subject: [jQuery] Re: Best Method to (re)bind event handlers You might find the copyEvents plugin of interest. http://brandon.jquery.com/plugins/copyEvents/ -- Brandon Aaron On 4/10/07, Olaf Gleba <[EMAIL PROTECTED]> wrote: > > Hi, > > the last two days i argue about how to handle (re)binding event > handlers in a most elegant and un-redundant way when i work with > asynchron injected files. I worked with prototype/Behaviour for the > last couple of month, so i need a good approach to refactor this > within jquery. > > So far a defined a function that is used as a callback on .load() > functions which load xhr injected files. Within this function > (rebindEventHandlers) i define every function that is in use within > the injected files (s. appended Example below). > > First problem is: I don't want to traverse everytime through all > functions defined within this rebindEventHandlers callback, because > there is possibly no need for all(!) functions to rebind in some > case. Of course this could be avoided by defining more callback > functions that each only contains the needed functions to rebind and > use these func. as separat callbacks. But i think thats ugly... > > Second problem is: Sometimes (for example the choosen .toogle() > functionality, s. below the example code) i'd like to avoid to define > 2 functions for overall 1 functionality. Thats ugly too ;) > > How do you handle this task? I appreciate any comments. Thx in advance. > > greets > Olaf > > > EXAMPLE (structure): > > $(function(){ > > var rebindEventHandlers = function() { > > // example func to toggle some xhr loaded content > $("a.toggleBelowLoadedContent").toggle(function(){ > var el = $(this).parent(); > $(el).next().fadeOut("fast"); > $(this).text('Show'); > return false; > }, function() { > var el = $(this).parent(); > $(el).next().fadeIn("fast"); > $(this).text('Hide'); > }); > }; > // EOF rebindEventHandlers > > // func outside the defined callback func > // loads the xhr file which contains the above toogle functionality > // present the rebindEventHandlers as the callback > $("a#client").click(function(){ > $("div#account").load("/clients/dashboard/client/", > rebindEventHandlers); > }); > > > // example func to toggle some content on normal loaded sites > // See "Second problem"... > $("a.toggleBelow").toggle(function(){ > var el = $(this).parent(); > $(el).next().fadeOut("fast"); > $(this).text('Show'); > return false; > }, function() { > var el = $(this).parent(); > $(el).next().fadeIn("fast"); > $(this).text('Hide'); > }); > > }; > // EOF document.ready() > > > > > > > >