Javascript DOM HTML Element setAttribute() Method update input button

Introduction

Change an input field to an input button:

document.getElementsByTagName("INPUT")[0].setAttribute("type", "button");

Click the button below to change the input field to an input button.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input value="OK">
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {// w  ww .jav a 2 s.c o m
  document.getElementsByTagName("INPUT")[0].setAttribute("type", "button");
}
</script>

</body>
</html>



PreviousNext

Related