How can I alert the id of the item clicked?
- First
- Second
If you change your html code a bit - remove the ids
- First
- Second
- Third
- Fourth
- Fifth
Then the jquery code you want is...
$("#myid li").click(function() {
alert($(this).prevAll().length+1);
});
You don't need to place any ids, just keep on adding li items.
Take a look at demo
Useful links