Javascript DOM HTML Fieldset name Property set

Introduction

Change the value of the name attribute of a fieldset:

document.getElementById("myFieldset").name = "newName";

Click the button to display the new name of the fieldset.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form>
<fieldset id="myFieldset" name="MyNameFieldset">
  Name: <input type="text" name="username"><br>
  Email: <input type="text" name="usermail"><br>
</fieldset>
</form>/*from  w ww  .j  av a  2s. com*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myFieldset").name = "newName";
  document.getElementById("demo").innerHTML = document.getElementById("myFieldset").name;
}
</script>

</body>
</html>



PreviousNext

Related