HTML DOM Legend Object

HTMLWeb DevelopmentFront End Technology

The HTML DOM Legend Object in HTML represents the <lagend> element.

Syntax

Following is the syntax −

Creating a <legend> element

var legendObject = document.createElement(“LEGEND”)

Properties

Here, “LegendObject” can have the following properties −

PropertyDescription
formIt returns a reference of enclosing form that contains the legend element

Example

Let us see an example for Legend form property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Legend form</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form id="Mid-Term">
<fieldset>
<legend id="legendForm">Legend-form</legend>
<label for="WeekSelect">Examination Week:
<input type="week" value="2019-W36">
</label>
<input type="button" onclick="showExamination()" value="What exams are in this week? ">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var legendForm = document.getElementById("legendForm");
   function showExamination() {
      divDisplay.textContent = 'Examinations: '+legendForm.form.id;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘What exams are in this week?’ button −

After checking ‘What exams are in this week?’ button −

raja
Published on 30-Jul-2019 15:17:20
Advertisements