The HGroup object represents an HTML <hgroup> element.
The HGroup object supports the standard properties and events.
We can access a <hgroup> element by using getElementById().
<!DOCTYPE html>
<html>
<body>
<hgroup id="myHgroup">
<h1>header 1</h1>
<h2>header 2</h2>
</hgroup><!-- ww w. ja va 2 s. c om-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myHgroup").innerHTML;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create a <hgroup> element by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- w w w . j a v a 2 s. c o m-->
var x = document.createElement("HGROUP");
document.body.appendChild(x);
var elemh1 = document.createElement("H1");
var txt = document.createTextNode("H1");
elemh1.appendChild(txt);
x.appendChild(elemh1);
var elemh2 = document.createElement("H2");
var txt2 = document.createTextNode("H2");
elemh2.appendChild(txt2);
x.appendChild(elemh2);
}
</script>
</body>
</html>
The code above is rendered as follows: