Get Legend Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Legend

Introduction

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>
<html>
<body>

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

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

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

<script>
function myFunction() {//from   w w  w  .  j  av a2s  .  c o  m
    var x = document.getElementById("myLegend").innerHTML;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials