CKTIS / JavaScript
HTMLButtonElement.form — the form associated with a button
The read-only HTMLButtonElement.form property returns the HTMLFormElement associated with a button, or null. It identifies the actual form rather than the text value of the form attribute.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
button.formHTMLButtonElement.form, read as button.form, returns the button's form owner: an HTMLFormElement object, or null when there is no association. Check for null before accessing the form's properties.
By default, a button belongs to its nearest ancestor form. The form attribute can identify a form's id in the same document, even outside that ancestry, and override the default association. button.getAttribute("form") reads the attribute text, not the form object.
The property is read-only: do not assign to button.form. Change the form attribute or the button's DOM position instead. The example shows association and its removal. This is a browser API defined by HTML, not an ECMAScript language feature; MDN marks it as widely available since July 2015.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Button form owner</title>
<form id="profile"></form>
<button type="button" id="save">Save</button>
<script>
const button = document.getElementById("save");
const form = document.getElementById("profile");
console.log(button.form === null);
button.setAttribute("form", "profile");
console.log(button.form === form);
console.log(button.getAttribute("form"));
button.removeAttribute("form");
console.log(button.form === null);
</script>
</html>Result
true true profile true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.