Hi Mike, thanks for this, this solution sounds quite plausible and is a good way to handle it at the moment, so thank you again!
Best regards Arne > -----Original Message----- > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of Mike Alsup > Sent: Sunday, June 17, 2007 7:17 PM > To: jquery-en@googlegroups.com > Subject: [jQuery] Re: Refreshing event registration > > > Arne, > > When jQuery 1.1.3 comes out you will be able to use Brandon Aaron's > Behavior Pluigin[1] to manage this behavior automatically. Until then > you can do it manually. They key is to only bind the elements that > have not been previously bound. If, for example, you're using ajax > functionality to replace the contents of a form you can do something > like the following: > > function addBehavior(sel, context) { > $(sel, context).click(function(){}); > } > > $(document).ready(function() { > addBehavior(':input'); > > // example 1: load method > $('#example1').click(function() { > $('#myForm').load(function() { > addBehavior(':input',this); > }); > }); > > // example 2: simple form plugin usage > $('#example2').submit(function() { > $('#myForm').ajaxSubmit(function() { > addBehavior(':input',this); > }); > return false; > }); > > // example 3: advanced form plugin usage > $('#example2').submit(function() { > $('#myForm').ajaxSubmit({ > target: '#myForm', > success: function() { > addBehavior(':input',this); > } > }); > return false; > }); > }); > > > If you're just adding some elements on the fly they you'll need to be > slightly more clever but as long as you know what you've added you > should be able to either cache them or select them and apply the > desired behavior. > > // cache example > var $a = $('<input name="a" value="x">').appendTo('#myForm'); > var $b = $('<input name="b" value="y">').appendTo('#myForm'); > > addBehavior([$a,$b]); > > > > Cheers. > > Mike > > [1] > http://jqueryjs.googlecode.com/svn/trunk/plugins/behavior/jquery.behavi > or.js > > > > > On 6/17/07, Arne-Kolja Bachstein <[EMAIL PROTECTED]> wrote: > > > > > > > > > > Hi there, > > > > > > > > I am adding input elements using jQuery and these input elements > shall react on globally registered event handlers ( > $(".myelement").click() ). But when inserting them via jQuery, they do > not react on these rules, so I think I have to somehow re-register the > events after adding them dynamically. But how do I do this? When I > simply execute the bindings after inserting the elements, the events > get registered multiple times. Is there a simple re-register command or > something? > > > > > > > > Thanks in advance > > > > > > > > Arne > > > > > > > >