SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [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
    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?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe
    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);
    					$("#" + 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);
    																}	
    															});
    													});
    				}	
    			});
    	});

  3. #3
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wo! that's goes endless, it is not dynamic..
    Im working on a tree list..

  4. #4
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    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);
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  5. #5
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did it like a charm!
    thank you

  6. #6
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •