Button type Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button

Description

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

Set the type property with the following Values

Value Description
submit The button is a submit button
button The button is a clickable button
reset The button is a reset button

Return Value

A String, representing the button type

The following code shows how to return the type of a button:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="#">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button id="myBtn" type="button" value="Reset">Reset</button>
</form>/*from w w  w .j  a v  a  2  s  .  c o m*/

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myBtn").type;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials