Javascript DOM HTML Variable Object create

Introduction

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

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {// ww w  . java  2  s . c o  m
  var x = document.createElement("VAR");
  var t = document.createTextNode("Some text..");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related