Create a Legend Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Legend

Introduction

You can create a <legend> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<fieldset id="myFieldset">
  Name: <input type="text">
</fieldset><br>

<button onclick="myFunction()">create a LEGEND element with some text</button>

<script>
function myFunction() {/*w w w .  j  a  v  a2  s  . co m*/
    var x = document.createElement("LEGEND");
    var t = document.createTextNode("Personalia:");
    x.appendChild(t);
    document.getElementById("myFieldset").appendChild(x);
}
</script>

</body>
</html>

Related Tutorials