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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!