Button formProperty

Button 对象参考手册Button Object

Definition and Usage

The form property returns a reference to the form that contains the button.

If the button is contained in a form, a form object is returned; if the button is not contained in a form, null is returned.

Syntax

buttonObject.form


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the form property.


Example

Example

The following example returns the id of the form to which the button belongs:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
</head>
<body>

<form id="form1">
<button id="button1" type="button">Click me!</button>
</form>
<p>The ID of the form containing the button:
<script>
document.write(document.getElementById("button1").form.id);
</script></p>

</body>
</html>

Try it yourself »


Button 对象参考手册Button Object Other Extensions