String sub() Method - Javascript String

Javascript examples for String:sub

Description

The sub() method displays a string as subscript text.

This method returns the string embedded in the <sub> tag, like this:<sub>string</sub>

Parameters

None.

Return Value:

A string embedded in the <sub> tag

The following code shows how to Display a string as subscript text:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//w  w w .j  av  a  2  s .c  om
    var str = "Hello World!";
    var result = str.sub();
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials