how to do a same loop action? thank you.
$('a.level').click(function() {
var level = $(this).parent('li').attr("class");
var nxvl = parseInt(level)+1;
var dir = $(this).html();
var curr = $(this);
var data = new Object();
data.n = new Date().getTime();
data.act = "getdirectory";
data.level = level;
data.direct = dir;
var str = $.toJSON(data);
$.post('ajax.php', { str: str }, function(result){
var data = eval('('+obj.data+')');
var html = [];
$.each(data, function(key, value) {
html[key] = "<li class='"+nxvl+"'><a href='javascript:void(0);' title='' class='level'>"+eval(value)+"</a><ul></ul></li>";
});
$(curr).next('ul').html(html.join(""));
$('a.level').click(function() {
// do the same action
}
});
return(false);
});
In this case, you probably want to use live handlers. Change your outer:
To:
Then you don’t worry about adding new click handlers after you’ve updated the HTML in
$(curr).next('ul').html(...)