开发者

incremental OL using letters (jQuery)

开发者 https://www.devze.com 2022-12-30 18:09 出处:网络
I\'m trying to dynamically add a span to an ol, where the counter should be in letters. eg: A result B result

I'm trying to dynamically add a span to an ol, where the counter should be in letters. eg: A result B result C result etc etc

I've got this code which is great for using numbers but I've no idea what to do to it to make the numbe开发者_如何转开发rs 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 greatly appreciated!


Use the 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>');
       });
    });
})

Upper Case:

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'll run out of letters if you have more than 26 results.

0

精彩评论

暂无评论...
验证码 换一张
取 消