Get Legend Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Legend


The Legend object represents an HTML <legend> element.

You can access a <legend> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

  <legend id="myLegend">Personalia:</legend>
  Name: <input type="text">

<button onclick="myFunction()">get the text of the legend element</button>

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

function myFunction() {//from  w ww  .  j  a  va 2 s  . c  om
    var x = document.getElementById("myLegend").innerHTML;
    document.getElementById("demo").innerHTML = x;


Related Tutorials