JQuery sub() Method
Last Updated :
09 Jan, 2023
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 =
</ script >
< 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 >
|
Output:
Example 2: In this example, we will see the use of the JQuery sub() method.
html
< script src =
</ script >
< 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 >
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...