Javascript DOM HTML Samp Object get

Introduction

The Samp object represents an HTML <samp> element.

We can access a <samp> element via document.getElementById():

var x = document.getElementById("mySamp");

Click the button to set the color of the formatted text to red.

View in separate window

<!DOCTYPE html>
<html>
<body>
<samp id="mySamp">this is a test</samp>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  w  ww  .  ja v a  2 s  . c o m
  var x = document.getElementById("mySamp");
  x.style.color = "red";
}
</script>

</body>
</html>



PreviousNext

Related