Javascript DOM HTML Button type Property get

Introduction

Return the type of a button:

var x = document.getElementById("myBtn").type;

Click the button to return the value of its type attribute.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button type="button" id="myBtn" onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*w  w  w  .j  a v  a  2  s  .  co  m*/
  var x = document.getElementById("myBtn").type;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The type property sets or gets the type of a button.

Always specify the type attribute for the button.

Property Values

Value Description
submit The button is a submit button (default for all browsers, except Internet Explorer)
button The button is a clickable button (default for Internet Explorer)
reset The button is a reset button (clears form data)



PreviousNext

Related