Javascript Reference - HTML DOM Fieldset Object








The Fieldset object represents an HTML <fieldset> element.

Fieldset Object Properties

Property Description
disabled Sets or gets whether a fieldset is disabled
form Returns a reference to the form that contains the fieldset
name Sets or gets the name attribute of a fieldset
type Returns element type

Standard Properties and Events

The Fieldset object supports the standard properties and events.

Example

We can access a <fieldset> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<fieldset id="myFieldset" name="information">
  Name: <input type="text" name="username"><br>
  Email: <input type="text" name="usermail"><br>
</fieldset>
<button onclick="myFunction()">test</button>
<!--from  w  w  w. j ava 2  s. c  om-->
<script>
function myFunction() {
    var x = document.getElementById("myFieldset");
    x.disabled = true;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <fieldset> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from  www . ja  v  a2 s .c  o  m-->
    var x = document.createElement("FIELDSET");
    var t = document.createTextNode("content here...");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: