hphoeksma wrote: > Hi all, > > new to jQuery I am having difficulty on the binding concept. > > Currently using this function to regenerate a full form based on a PHP > script. > > -- > $("select").change(function () { > $.get('script.php', {'c': c, 'sc': sc }, function(data) { > $('form').html(data); > }); > return false; > }) > .change(); > -- > This works, but I'd like to use some next steps in the newly created > selectors. > > I understand I need to (re)bind these selectors, but am lost on how to > achieve that. Anyone? > > Thanks in advance, > > Henjo
This is what work for me: 1. I write all the js code near the element that need it. In your case, I will write the jquery code soon after the </select> tag. The code will be like this: <select ....> ... </select> <script type="text/javascript"> jquery(function($){ $("select").change(function(){ .... }); }); </script> 2. When I do ajax that will replace the current DOM element, I will also send the code for the new element in the XMLHttpRequest response. In your case above, the script.php will return data to .get like this: ..... <select ....> ... </select> <script type="text/javascript"> jquery(function($){ $("select").change(function(){ .... }); }); </script> ...... With this approach, the injected data will bring all the needed code for it's element. I use this for form, list with pagination, and all other XMLHttpRequest. Writing js code near element that need it, beside maintain the unobtrusive, also made debugging it easier. I hope this will work with your case. -- Donny Kurnia http://hantulab.blogspot.com http://www.plurk.com/user/donnykurnia