Jquery expand/collapse on dynamically generated list

My script uses an Ajax GET command to pull data from an Excel spreadsheet and then display it as a series of lists and sublists. The script creates a string with the necessary HTML and then inserts it into a DIV. How can I implement an expand/collapse function for the lists? All the Jquery examples I’ve seen seem to work with static lists. The function would have to be placed inside the GET block.

I think I found the solution:

$("#divID").ready(function () {
            $("#divID").find('li:has(ul)').click(function (event) {

(event code goes here)

            });
        });