Selector cannot find ajax element?

Selector cannot find ajax element?

  1. function GetDepartmentTree() {
        $.ajax({
            type: "POST",
            url: "Service/service.asmx/GetDepartmentTree",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: "",
            success: function(data) {
                $(".DivTreeView").html(data.d);
            },
            error: function(x, e) {
                alert(x.responseText);
            },
            complete: function(x) {
                alert(x.responseText);
            }
        });
    }
















  2.             $("#NavigationDepartmentList span").click(function() {
                    alert($(this).text());
                });

It is not work.
  1. $(".DivTreeView").html("<ul id='NavigationDepartmentList'><li><span>span1</span><ul> <li><span>span2</span><ul></ul>");
  2.             $("#NavigationDepartmentList span").click(function() {
                    alert($(this).text());
                });

It work fun.