Javascript DOM HTML Input Week Object create

Introduction

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

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

Click the button to create a Week field.

View in separate window

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

<script>
function myFunction() {//from  ww w  .j  av  a 2s .  c o  m
  var x = document.createElement("INPUT");
  x.setAttribute("type", "week");
  x.setAttribute("value", "2000-W35");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related