[jQuery] recursive function

Hello
I’m not sure of the title really refers to my issue, but I simply have a click function that adds more text to the page, that text has to use the same function that it wrote it.

This is an extract from my code


$("a").click(function() { 
		liid = $(this).attr("id"); 
		$.ajax({method: "get", 
			url: "file.php",
			data: "id=" + liid,
			beforeSend: function() { $("#icon_" + liid).attr("src", "img/loading.gif"); },
			complete: function() { $("#icon_" + liid).attr("src", "img/icon.png"); },
			success: function(returnedData)
				{						
					$("#" + liid + "_new").html(returnedData);
				}	
			});
	});

On success, some links will be written into the page, if you click on those link, they should use the same function, but how to make the whole thing to recognize the new text so that the function can load whenever you click on the new links?

Maybe


$("a").click(function() {
		liid = $(this).attr("id");
		$.ajax({method: "get",
			url: "file.php",
			data: "id=" + liid,
			beforeSend: function() { $("#icon_" + liid).attr("src", "img/loading.gif"); },
			complete: function() { $("#icon_" + liid).attr("src", "img/icon.png"); },
			success: function(returnedData)
				{						
					$("#" + liid + "_new").html(returnedData);
					$("#" + liid + "_new > a").click(function() {
														liid = $(this).attr("id");
														$.ajax({method: "get",
															url: "file.php",
															data: "id=" + liid,
															beforeSend: function() { $("#icon_" + liid).attr("src", "img/loading.gif"); },
															complete: function() { $("#icon_" + liid).attr("src", "img/icon.png"); },
															success: function(returnedData)
																{						
																	$("#" + liid + "_new").html(returnedData);
																	$("#" + liid + "_new > a").html(returnedData);
																}	
															});
													});
				}	
			});
	});

Wo! that’s goes endless, it is not dynamic…
Im working on a tree list…


function anchorClick() {
    liid = $(this).attr("id"); 
    $.ajax({method: "get", 
        url: "file.php",
        data: "id=" + liid,
        beforeSend: function() { $("#icon_" + liid).attr("src", "img/loading.gif"); },
        complete: function() { $("#icon_" + liid).attr("src", "img/icon.png"); },
        success: function(returnedData)
            {                        
                $("#" + liid + "_new").html(returnedData);
                $("a").click(anchorClick);
            }
    });
}
$("a").click(anchorClick);

That did it like a charm!
thank you

thank helped me soooooooo much!! I have been looking for an answer to this for a whole day thank you JimmyP, you’re a genius!!