Javascript DOM HTML Input Color Object create

Introduction

The Input Color object represents an HTML <input> element with type="color".

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

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

Click the button to create a Color picker.

View in separate window

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

<script>
function myFunction() {//  ww  w .jav  a2 s  .  c  om
  var x = document.createElement("INPUT");
  x.setAttribute("type", "color");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related