Not sure if JavaScript exposes that, but you could do
$('li').each(function(i) {
$(this).click(function() {
var item = String.fromCharCode(97 + i);
alert(item);
});
});
What this does it attach a click event to each li
, and has the value i
set as its index.
When you click one, it gets the lowercase a which has 97
charCode, and then adds the index which gives you a letter.
See an example on JSbin.
Note After 26 list items, you are going to get characters like {
, etc, whereas using CSS's lower-alpha
will give you aa
, ab
etc. (see example on JSbin). You would need to modify the code to suit if you had more than 26 list items.