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 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 > w3wiki </ h1 > < h2 > HTML DOM Samp Object </ h2 > < samp id = "Beginner" > A computer science portal for Beginner </ samp > < br >< br > < button onclick = "myBeginner()" > Submit </ button > < script > function myBeginner() { let txt = document.getElementById("Beginner"); 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 >w3wiki</ h1 > < h2 >DOM Samp Object</ h2 > < button onclick = "myBeginner()" > Submit </ button >< br > < script > function myBeginner() { let cont = document.createElement("SAMP"); let txt = document.createTextNode( "A Computer SciencePortalForBeginner"); 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