Hi all,

I have a link that triggers an AJAX call when clicked to add some more
HTML to a form. I do this by replacing the link with the added details
and the link itself. How do I re-attach this on click event to the
html that I have just inserted.

HTML is

<div id="add_another">
<a href="#add_another" name="add_another">Add another person</a>
</div>

Jquery code is:

jQuery(document).ready(function() {
               jQuery("#add_another").click(function() {

jQuery.getJSON("/index.php?option=com_eventbooking&format=raw",
function(data) {
                       jQuery("#add_another").replaceWith(data[0]);

/*I tried this, which works once */
                       jQuery("#add_another").click(function() {

               jQuery.getJSON("/index.php?option=com_eventbooking&format=raw",
function(data) {
                               jQuery("#add_another").replaceWith(data[0]);
                       });
               });

           });
     });
});

AJAX output  is

<?php
echo json_encode(array('more text here<div id="add_another">
       <a name="add_another" href="#add_another">Add another person</a>
       </div>'));


Kind Regards,

Jochen Daum

"There is no shortcut to anywhere worth going" - Beverly Sills

Automatem Ltd
Phone: 09 630 3425
Mobile: 021 567 853
Email: [email protected]
Website: www.automatem.co.nz
http://nz.linkedin.com/in/automatem
http://twitter.com/automatem
http://www.aucklandbusinessnetworking.co.nz

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to