K Stewart K Stewart - 1 year ago 109
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>";


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download