Javascript DOM HTML Superscript Object create

Introduction

We can create a <sup> element via the document.createElement() method:

var x = document.createElement("SUP");

Click the button to create a SUP element with some text.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {// w  ww .j  av  a2  s  .  c o m
  var x = document.createElement("SUP");
  var t = document.createTextNode("This text contains superscript text");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related