Javascript DOM HTML Input Email Object create

Introduction

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

Click the button to create an Email field.

View in separate window

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

<script>
function myFunction() {//  ww  w .  ja  va  2 s. c o m
  var x = document.createElement("INPUT");
  x.setAttribute("type", "email");
  x.setAttribute("value", "john@example.com");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related