We can create a <sub> element via the document.createElement()
method:
var x = document.createElement("SUB");
Click the button to create a SUB element with some text.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w ww . j a v a2s .co m*/ var x = document.createElement("SUB"); var t = document.createTextNode("This text contains subscript text"); x.appendChild(t); document.body.appendChild(x); } </script> </body> </html>