Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  121] [ 2]  / answers: 1 / hits: 44141  / 7 Years ago, thu, june 15, 2017, 12:00:00

I've been working on a small project for myself, and it consists of creating the alphabet. I don't want to hard code each individual letter in markup, but rather use JavaScript to do it for me.



This is how far I've gotten.



for ( i = 0; i < 26; i++ ) {



var li = document.createElement(li);
li.innerHTML = letter + i + ;
li.style.listStyle = none;
li.style.display = inline;
document.getElementById(letter-main).appendChild(li);

}


That being said, I'm trying to avoid using jQuery for the time, as I am trying to gain a better understanding of JavaScript.



There's another post that goes over the same Idea, using character codes but with jQuery.



How would I go about this?


More From » loops

 Answers
27

You can use toString() to convert a number to alpha





for (i = 0; i < 26; i++) {

var li = document.createElement(li);
li.innerHTML = letter + (i+10).toString(36) + ;
li.style.listStyle = none;
li.style.display = inline;
document.getElementById(letter-main).appendChild(li);

}

<div id=letter-main></div>




[#57439] Wednesday, June 14, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;