Javascript DOM HTML Subscript Object create

Introduction

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.

View in separate window

<!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>



PreviousNext

Related