Javascript Reference - HTML DOM Samp Object








The Samp object represents an HTML <samp> element.

Standard Properties and Events

The Samp object supports the standard properties and events.

Example

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:





Example 2

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: