Javascript code (using jQuery)
// Let's build a function for building the alphabet array
function getAlphabet(first, last) {
var alphabet = [];
for (i = first.charCodeAt(0); i <= last.charCodeAt(0); ++i) {
alphabet.push(String.fromCharCode(i));
}
return alphabet;
}
// Calling the function
var alphabet = getAlphabet('A', 'Z'); // ["a", ..., "z"]
// Printing the array inside the .letters element
$.each(alphabet, function (index, element) {
$(".letters").append("<div>" + element + "</div>");
});
Try it on JSFiddle.
Explanation
I have made a function that is able to build an array containing the alphabet. Then, we store that in a variable and, finally, we use jQuery .each()
method that allows us to go throw the array and, inside each iteration, we can use .append()
in order to add the letters inside the div.