Javascript DOM HTML HR Object create

Introduction

We can create a <hr> element via the document.createElement() method:

var x = document.createElement("HR");

Click the button to create a HR element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/* w  w w  .  j  ava 2  s.co  m*/
  var x = document.createElement("HR");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related