I am trying to list use the counter in a for loop as the number of a unicode character. The purpose of this, ...lets just say I am doing it for fun. Surely, a seasoned javascript user will be able to tell me what is wrong here.
To use a unicode character in javascript one can either type it in as it is, or use an escape sequence like: \u8211
. My problem arises when I try to combine the number part with the escaped u. The error I get is something along the lines of "bad escape character", and it means that the number from the i
variable is not combined with the \u
as I'm hoping for.
for (var i=65; i< 90; i++ ) {
anchor = document.createElement('a'),
img = document.createElement('img'),
character = "\\u"+i;
img.setAttribute('alt', character);
img.setAttribute('src', '');
anchor.appendChild(document.createTextNode(i +": "));
anchor.appendChild(img);
anchor.setAttribute('title', character);
body.appendChild(anchor);
body.appendChild(document.createElement('br'));
}
What I have tried:
character = "\u{"+i+"}"
cha = ['\\u'];
cha.push(i);
cha.join('');
... and i've run out of ideas
An example:
jsfiddle.net/Dn4Vv/