The Samp object represents an HTML <samp> element.
The Samp object supports the standard properties and events.
We can access a <samp> element by using getElementById().
<!DOCTYPE html>
<html>
<body>
<samp id="mySamp">this is a test</samp>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- ww w. j a v a2 s . c o m-->
var x = document.getElementById("mySamp");
x.style.color = "blue";
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create a <samp> element by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w w .ja v a 2s. com-->
var x = document.createElement("SAMP");
var t = document.createTextNode("this is a test");
x.appendChild(t);
document.body.appendChild(x);
}
</script>
</body>
</html>
The code above is rendered as follows: