JavaScript sup method

In the JavaScript, method sup() method is used to format text in superscript format.

JavaScript sup method

JavaScript sup method

     

In the JavaScript, method sup() method is used to format text in superscript format. It makes a copy of that string and then embed it within <sup></sup> tags as in HTML.

Syntax:

 String_Object.sup();

It returns the copy of string in the superscript format.

Description of code:

Here we have created an input text and button. We have to supply string into the input text to convert them into superscript format. Click on the button to call the function superscriptText() as defined in the JavaScript within the <script></script> tags. It takes the text string into a variable textToSuperscript and there after we have converted the string into superscript format by calling method sup() on the string reference object. Here is the full HTML code as follows :

superscriptExample.html

<html>
<head>
 <title>
   Convert string to superscript
 </title>
 <script language="JavaScript">
 function superscriptText()
 {
  var textToSuperscript = document.getElementById('txt').value;
  document.write("<p> Superscript text "+
           textToSuperscript.sup()+"</p>");
 }
 </script>
</head>
<body>
<div style="background: #ff9900; width:'100%';"
    align="center">
  <font color="#0000ff" size="12pt">
	<b>sup() Example</b>
  </font>
</div>
 <center>
  Insert any text 
 <input type="text" id="txt" /><br>
 <div id="divId" style="backgroud :#ccccff"></div>
 <input type="button" value="Convert text to superscript"
   onClick="return superscriptText();"/>
 </center>
 </body>
</html>

Output:

Insert any text to format them into superscript format and click on the button "Convert text to superscript" 

You can see from the following output that the text inserted "Welcome" is converted to the superscript format.

Download Source Code