Javascript DOM HTML Input Button Object create

Introduction

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

Click the button to create an Input Button with a "Click me" text.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/*from  w  w  w.jav  a 2s  . co m*/
  var x = document.createElement("INPUT");
  x.setAttribute("type", "button");
  x.setAttribute("value", "Click me");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related