I have the following:
item1 sub1 sub2
I think you need to use the each method. so try the following script:
$(document).ready(function() { $('ul').each(function() { $(this).find('li').click(function() { var listItem = this; alert($(listItem).text()); }); }) });
with the following markup
1 2 3 4