JQuery sub() Method

This sub() method in JQuery is used to display the string as subscript text. This method returns the string embedded in the tag, like this: <sub> string </sub>.

Syntax: 

string.sub()

Parameters: This method does not accept any parameter.

There are two examples discussed below:

Example 1: In this example, we will see the use of the JQuery sub() method.

html




<script src=
"https://code.jquery.com/jquery-3.5.0.js">
</script>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        w3wiki
    </h1>
    <p id="GFG_UP">
    </p>
    <button onclick="Beginner()">
        Click here
    </button>
    <p id="GFG_DOWN">
    </p>
    <script>
        var el_up = document.getElementById("GFG_UP");
        var el_down = document.getElementById("GFG_DOWN");
        var str = "Hello Beginner!";
        el_up.innerHTML = "JQuery | sub() method";
        function Beginner() {
            el_down.innerHTML = "Result is " + str.sub();
        }
    </script>
</body>


Output:

 

Example 2: In this example, we will see the use of the JQuery sub() method.

html




<script src=
"https://code.jquery.com/jquery-3.5.0.js">
</script>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        w3wiki
    </h1>
    <p id="GFG_UP">
    </p>
    <button onclick="Beginner()">
        Click here
    </button>
    <p id="GFG_DOWN">
    </p>
    <script>
        var el_up = document.getElementById("GFG_UP");
        var el_down = document.getElementById("GFG_DOWN");
        var str = "Hello Beginner!";
        el_up.innerHTML = "JQuery | sub() method";
        function Beginner() {
            el_down.innerHTML =
        "Some text " + str.sub() + " Some other text";
        }
    </script>
</body>


Output: