Button form Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button


The form property returns the form containing the button.

This property is read only.

Return Value

A reference to the form element containing the button. If the button is not in a form, null is returned

The following code shows how to return the id of the form the button belongs to:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form id="myForm">
  <button id="myBtn" type="button" onclick="myFunction()">Test</button>
</form>// w  w w .  j  a  v a 2s.  c  o  m

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

function myFunction() {
    var x = document.getElementById("myBtn").form.id;
    document.getElementById("demo").innerHTML = x;


Related Tutorials