Add a border to a <div> element:
document.getElementById("myDiv").style.border = "thick solid #0000FF";
<!DOCTYPE html> <html> <body> <div id="myDiv">This is a div element.</div> <br> <button type="button" onclick="myFunction()">Set border</button> <script> function myFunction() {/*from www. j a v a 2 s .c o m*/ document.getElementById("myDiv").style.border = "thick solid #0000FF"; } </script> </body> </html>
The border property sets or gets up to three separate border properties, in a shorthand form.
With this property, you can set/get one or more of the following:
Property Values
Parameter | Description |
---|---|
width | Sets the width of the borders |
style | Sets the style of the borders |
color | Sets the color of the borders |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The border property returns a String representing the border width, style and/or color of an element.