Incremental OL using letters (jQuery)

I am trying to dynamically add span to ol where the counter should be in letters. for example: Result B result Result C etc, etc.

I have this code that is great for using numbers, but I don’t know what to do with it to make numbers into letters

jQuery(document).ready( function() { jQuery('.results ol').each(function () { jQuery(this).find('li').each(function (i) { i = i+1; jQuery(this).prepend('<span class="marker">' + i + '</span>'); }); }); }); 

Any help is much appreciated!

+4
source share
1 answer

Use HTML codes :

Lower case:

 jQuery(document).ready( function() { jQuery('.results ol').each(function() { jQuery(this).find('li').each(function(i) { jQuery(this).prepend('<span class="marker">&#' + (i+97) + ';</span>'); }); }); }) 

Uppercase:

 jQuery(document).ready( function() { jQuery('.results ol').each(function() { jQuery(this).find('li').each(function(i) { i = i+1; jQuery(this).prepend('<span class="marker">&#' + (i+65) + ';</span>'); }); }); }) 

Of course, you will end the letter if you have more than 26 results.

+2
source

Source: https://habr.com/ru/post/1309936/


All Articles