K Stewart K Stewart - 9 months ago 57
jQuery Question

subscript format the last character in a string in jquery

Is there a relatively simple way in jquery to format the last character in a string as subscript using the ID tag. I have a dynamic table and some of the cells contain a string of a letter first and a number last and would like to display the number subscript. So the value B1 at '#B1' should be display as B 1.

Thanks in advance

Answer Source
t = "B1";
lastNumber = t.substr(t.length-1);
allCharsButLastNumber = t.slice(0, -1)
document.getElementById(t).innerHTML = allCharsButLastNumber+"<sub>"+lastNumber+"</sub>";