Javascript DOM HTML Input Search Object create

Introduction

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

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

Click the button to create a Search field.

View in separate window

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

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

</body>
</html>



PreviousNext

Related