Javascript DOM HTML Input URL Object create

Introduction

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

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

Click the button to create an URL field.

View in separate window

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

<script>
function myFunction() {//from   w w w . j a  v  a 2s  . c o m
  var x = document.createElement("INPUT");
  x.setAttribute("type", "url");
  x.setAttribute("value", "http://www.google.com");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related