HTML | DOM Samp Object
The Samp Object in HTML DOM is used to represent the <samp> element. The <samp> element can be accessed by using getElementById() method.
Syntax:
document.getElementById("ID");Where ID is assigned to the <samp> tag.
Example 1:
<!DOCTYPE html> <html> <head> <title> HTML DOM samp Object </title> </head> <body> <h1> GeeksforGeeks </h1> <h2> HTML DOM Samp Object </h2> <samp id = "geeks"> A computer science portal for Geeks </samp> <br><br> <button onclick = "myGeeks()"> Submit </button> <script> function myGeeks() { var txt = document.getElementById("geeks"); txt.style.color = "green"; txt.style.fontSize = "16px"; } </script> </body> </html> |
Output:
Before Click on the Button:
After Click on the Button :
Example 2: Samp Object can be created by using the document.createElement Method.
<!DOCTYPE html> <html> <head> <title> HTML DOM samp Object </title> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM Samp Object</h2> <button onclick = "myGeeks()"> Submit </button><br> <script> function myGeeks() { var cont = document.createElement("SAMP"); var txt = document.createTextNode( "A Computer SciencePortalForgeeks"); cont.appendChild(txt); document.body.appendChild(cont); } </script> </body> </html> |
Output:
Before Click on the Button :
After Click on the Button:
Supported Browsers: The browser supported by DOM Samp Object are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari


.png)
