JavaScript sup method entry instance (displays string as superscript)

  • 2020-03-30 04:08:15
  • OfStack

The sup method returns the superscript string defined using the HTML sup tag attribute. The syntax is as follows:


str_object.sup()

Note: this method does not conform to ECMA standards and is not recommended.

Example of sup method:


<script language="JavaScript">
document.write( ' The home of the script ' + ' Every bit of progress is a solid footprint on our road to success '.sup() );
</script>

Run the example and output:


The home of the script Every bit of progress is a solid footprint on our road to success

Tip: this method returns a superscript string defined using an HTML sup tag, meaning that you cannot directly change a string to a superscript style using this method. If you want to dynamically change the element font to superscript style, see the following example:

Change the way the text is aligned up and down (superscript/subscript)


<html> <script language="JavaScript"> function changFont( x ){
    document.getElementById("sub_title").style.verticalAlign = x;
} </script> <body>
<p>
<a onClick="changFont('sub');"> The subscript style </a> <a onClick="changFont('super');"> Superscript style </a>
</p>
<p>
The home of the script <span id="sub_title"> Every bit of progress is a solid footprint on our road to success </span>
</p>
</body>
</html>

In this example, JavaScript controls the way the text CSS is styled vertical-align to dynamically change the up and down alignment (superscript/subscript) of the font text.


Related articles: