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
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>