zeez
October 15, 2008, 4:33pm
1
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);
}
});
});
}
});
});
zeez
October 15, 2008, 5:01pm
3
Wo! that’s goes endless, it is not dynamic…
Im working on a tree list…
JimmyP
October 15, 2008, 7:20pm
4
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);
zeez
October 15, 2008, 7:30pm
5
That did it like a charm!
thank you
thn
February 11, 2010, 11:56am
6
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!!