On site: http://jonirautiainen.net/code_edit/ there on left is a panel which has a filetree.
.load('scandDir.php') loads new <ul><li></li></ul> elements from php-file.
The problem is that because this script is a loop it executes loadNew(); multiple times. Please check the problem live on page mentioned before. Click on those folders to open them and you will see those files showing up multiple times.
Script needs to be looped because .load is asynchronous. $(".file-tree a").on( won't let me select those new elements created by executing .load.
Is there any other way to do this?
function loadNew()
{
$(".file-tree a").on("click",function ()
{
var path = $(this).attr("title");
var folder = $(this).text();
var name = $(this).attr("name");
var id = $(this).parent().attr("id");
$("#testi").html(path + folder + name + id);
var liHtml = $(this).parent().html();
if(liHtml.match(/<ul /))
{
}else
{
if(name=="dir")
{
$("#hiddenDiv1").load("scanDir.php?path=" + path + "/" + folder, function() {
var hiddenDiv = $("#hiddenDiv1").html();
$("#" + id).append(hiddenDiv);
loadNew();
});
}
}
});
}
loadNew();