Javascript DOM HTML Samp Object create

Introduction

We can create a <samp> element via the document.createElement() method:

var x = document.createElement("SAMP");

Click the button to create a SAMP element with some text.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {// w  w w.  j a  v  a2 s.  c om
  var x = document.createElement("SAMP");
  var t = document.createTextNode("this is a test");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related