Create Input Button Field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Introduction

You can create a <input type='button'> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click the "Try it" button to create a BUTTON element with a "Click me" text.</p>

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

<script>
function myFunction() {/*  w  ww  .j a  v  a2s.  c om*/
    var x = document.createElement("INPUT");
    x.setAttribute("type","button");
    x.setAttribute("value","asdf");
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials