Javascript Reference - HTML DOM Input Button type Property








The type property returns the type of form element. For an input button this property will always return "button".

Browser Support

type Yes Yes Yes Yes Yes

Syntax

var v = buttonObject.type 

Return Value

A String type value representing the type of input button.





Example

The following code shows how to get the type of a button.


<!DOCTYPE html>
<html>
<body>
<input type="button" onclick="myFunction()" id="myBtn" value="test">
<p id="demo"></p>
<script>
function myFunction() {<!--from  ww  w  .  j  a v  a2 s.  c o m-->
    var x = document.getElementById("myBtn").type;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: