Javascript DOM HTML Input Submit Object create

Introduction

We can create an <input> element with type="submit" via the document.createElement() method:

var x = document.createElement("INPUT"); x.setAttribute("type", "submit");

Click the button to create a Submit Button.

View in separate window

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

<script>
function myFunction() {//from w  w  w .  j a v  a2 s  .co  m
  var x = document.createElement("INPUT");
  x.setAttribute("type", "submit");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related