How to find the id of the form a button belongs to in JavaScript?

HTMLJavascriptProgramming Scripts

To get the id of the form in JavaScript, use the id property.


You can try to run the following code to learn how to get the id of the form in JavaScript.

Live Demo

<!DOCTYPE html>
      <form id="myForm">
         <button id="btn" type="button">My Button</button>
         var str = document.getElementById("btn");
         document.write("Form id of above button: "+str);
Published on 26-Feb-2018 08:25:41