Create a Superscript Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Superscript

Introduction

You can create a <sup> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a SUP element with some text</button>

<script>
function myFunction() {//from  w  w  w. ja  v a2s.c om
    var x = document.createElement("SUP");
    var t = document.createTextNode("This text contains superscript text");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials