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()

There are two examples discussed below:

  • Example 1:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML> 
    <html>  
    <head
        <title
          JQuery | sub() method
        </title>      
        <script src=
        </script
    </head>   
    <body style="text-align:center;"
        <h1 style="color:green;">  
            GeeksForGeeks  
        </h1
        <p id="GFG_UP"
        </p>
        <button onclick="Geeks()"
            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 Geeks!";
            el_up.innerHTML = "JQuery | sub() method";
            function Geeks() {
                el_down.innerHTML = "Result is " + str.sub();
            
        </script
    </body>   
    </html>  

    chevron_right

    
    

  • Output:
  • Example 2:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML> 
    <html>  
    <head
        <title
          JQuery | sub() method
        </title>      
    </script
    </head>   
    <body style="text-align:center;"
        <h1 style="color:green;">  
            GeeksForGeeks  
        </h1
        <p id="GFG_UP"
        </p>
        <button onclick="Geeks()"
            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 Geeks!";
            el_up.innerHTML = "JQuery | sub() method";
            function Geeks() {
                el_down.innerHTML = 
    "Some text " + str.sub() + " Some other text";
            
        </script
    </body>   
    </html
      

    chevron_right

    
    

  • Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.