Javascript Reference - HTML DOM HR Object








The HR object represents an HTML <hr> element.

HR Object Properties

Property Description
align Not supported in HTML5. Use style.textAlign instead.
Sets or gets the alignment of a horizontal line
color Not supported in HTML5. Use style.color instead.
Sets or gets the color of a horizontal line
noshade Not supported in HTML5.
Sets or gets whether a horizontal line should render in a solid color without shading
size Not supported in HTML5. Use style.height instead.
Sets or gets the height of a horizontal line
width Not supported in HTML5. Use style.width instead.
Sets or gets the width of a horizontal line




Standard Properties and Events

The HR object supports the standard properties and events.

Example

We can get a <hr> element by using getElementsByTagName().


<!DOCTYPE html>
<html>
<body>
<hr><hr><hr><hr><hr>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- w w  w . j ava 2  s . c  o  m-->
    var x = document.getElementsByTagName("HR")[0];
    x.style.display = "none";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <hr> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<!--   w w w.  j ava 2s . co  m-->
<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    var x = document.createElement("HR");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: