I use this to number divs that have the class "number":
$("#parent .number").each(function(i){
$(this).html((i+1) + ". ");
});
but how would I use something similar to instead "number" as a,b,c,d etc?
Use string.fromCharCode:
$("#parent .number").each(function(i){
$(this).html(String.fromCharCode(97 + i) + ". ");
});
Also, if you would like to use capitalized characters, then use 65 instead of 97.
You can create an array of alphabet characters:
var alpha = ["a","b","c",....];
then use the index to print them:
$("#parent .number").each(function(i){
$(this).html(alpha[i] + ". ");
});
Just so you know, you can use an ordered list to do this using html and css:
The html:
<ol class="alpha">
<li>text ...</li>
<li>text ...</li>
<li>text ...</li>
<li>text ...</li>
</ol>
the css:
ol.alpha li {
list-style-type:lower-alpha;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With