Create a Legend Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Legend


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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

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

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

function myFunction() {//from   w  ww.  j a v  a  2 s  . co  m
    var x = document.createElement("LEGEND");
    var t = document.createTextNode("Personalia:");


Related Tutorials