how to draw a horizontal line in javascript

JavaScript
var elem = document.createElement("hr");
elem.setAttribute("width", "100px");
document.body.appendChild(elem);
Source

Also in JavaScript: