Open In App

JQuery sub() Method

Last Updated : 19 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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
<!DOCTYPE html>
<html lang="en">

<head>
    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</head>

<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>

    <button onclick="Geeks()">
        Click here
    </button>
    
    <p id="res"></p>

    <script>
        let result = document.getElementById("res");
        let str = "Hello Geeks!";

        result.innerHTML = "JQuery | sub() method";
        function Geeks() {
            result.innerHTML = "Result is " + str.sub();
        }
    </script>
</body>

</html>

Output:

JQuery-sub()-Method

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

html
<!DOCTYPE html>
<html lang="en">

<head>
    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</head>

<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>

    <button onclick="Geeks()">
        Click here
    </button>
    
    <p id="res"></p>

    <script>
        let result = document.getElementById("res");
        let str = "Hello Geeks!";

        result.innerHTML = "JQuery | sub() method";
        function Geeks() {
            result.innerHTML = "Some text " 
              	+ str.sub() + " Some other text";
        }
    </script>
</body>

</html>

Output:

JQuery-sub()-Method---2


Next Article

Similar Reads