Open In App

HTML DOM Samp Object

Last Updated : 15 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Samp Object in HTML DOM is used to represent the <samp> element. The <samp> element can be accessed by using the getElementById() method. 

Syntax:

document.getElementById("ID");

Where ID is assigned to the <samp> tag. 

Example 1: In this example, we will use the DOM Samp Object.

HTML




<!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() {
            let txt = document.getElementById("geeks");
            txt.style.color = "green";
            txt.style.fontSize = "16px";
        }
    </script>
</body>
   
</html>


Output:  

 

Example 2: Samp Object can be created by using the document.createElement Method. 

HTML




<!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() {
            let cont = document.createElement("SAMP");
            let txt = document.createTextNode(
                "A Computer SciencePortalForgeeks");
            cont.appendChild(txt);
            document.body.appendChild(cont);
        }
    </script>
</body>
 
</html>


Output:

 

Supported Browsers: The browser supported by DOM Samp Object are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads