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.
<!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>