Return which type of form element the fieldset is:
var x = document.getElementById("myFieldset").type;
Click the button to display which type of form element the fieldset is.
<!DOCTYPE html> <html> <body> <form> <fieldset id="myFieldset"> <legend>MyNameFieldset:</legend> Name: <input type="text"><br> Email: <input type="text"><br> Date of birth: <input type="text"> </fieldset> </form>// w w w. j ava 2 s . c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myFieldset").type; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The type
property returns which type of form element a fieldset is.
For a fieldset, this property will always return "fieldset".
This property is read only.