[an error occurred while processing this directive]

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.



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 :


   Convert string to superscript
 <script language="JavaScript">
 function superscriptText()
  var textToSuperscript = document.getElementById('txt').value;
  document.write("<p> Superscript text "+
<div style="background: #ff9900; width:'100%';"
  <font color="#0000ff" size="12pt">
	<b>sup() Example</b>
  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();"/>


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


[an error occurred while processing this directive]