SoFunction
Updated on 2025-04-03

JavaScript sup method beginner example (show strings as superscripts)

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

Copy the codeThe code is as follows:

str_object.sup()

Tip: This method does not comply with ECMA standards and is not recommended.

sup method example:

Copy the codeThe code is as follows:

<script language="JavaScript">
('I' + 'Every little progress is a solid footprint on our road to success'.sup() );
</script>

Run this example and output:

Copy the codeThe code is as follows:

IEvery little progress is a solid footprint on our road to success

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

Change the up and down alignment of font text (superscript/subscript)

Copy the codeThe code is as follows:

<html>

<script language="JavaScript">

function changFont( x ){
    ("sub_title"). = x;
}

</script>

<body>
<p>
<a onClick="changFont('sub');">Subscript style</a> <a onClick="changFont('super');">Superscript style</a>
</p>
<p>
Every little progress I make is a solid footprint on our road to success</span>
</p>
</body>
</html>

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