The HTML DOM borderTopStyle property is used for setting or returning the Top border style for an element.
Following is the syntax for −
Setting the borderTopStyle property −
object.style.borderTopStyle = value
The above properties are explained as follows −
Value | Description |
---|---|
None | This is the default value specifying no border. |
Hidden | This is same as "none" but will still take border space. It is basically transparent but still there. |
Dotted | This defines a dotted border. |
Dashed | This defines a dashed border. |
Solid | This defines a solid border. |
Double | This defines a double border |
Groove | This defines a 3d groove border and is the opposite of ridge. |
Ridge | This defines a 3D ridged border and is the opposite of groove |
Inset | This defines a 3D inset border and the effect looks like it is embossed. It produces the opposite effect of inset. |
outset | This defines a 3D inset border and the effect looks like it is embossed. It produces the opposite effect of inset. |
initial | For setting this property to initial value. |
inherit | To inherit the parent property value |
Let us look at an example for the borderTopStyle Property minus;
Example
<!DOCTYPE html> <html> <head> <style> #DIV1{ width:300px; height:100px; border-top: 8px solid dodgerblue; border-top-style: groove; } </style> <script> function changeTopStyle(){ document.getElementById("DIV1").style.borderTopStyle="dashed"; document.getElementById("Sample").innerHTML="The Top border style is now changed"; } </script> </head> <body> <div id="DIV1">SOME SAMPLE TEXT</div> <p>Change the above div Top border style by clicking the below button</p> <button onclick="changeTopStyle()">Change Top Style</button> <p id="Sample"></p> </body> </html>
Output
On clicking the “Change Top Style” button −
In the above example −
We have first created a div with id “DIV1” and apply a CSS style to it based on its id. The style contains the border-top style and its width mainly −
#DIV1{ width:300px; height:100px; border-top: 8px solid dodgerblue; border-top-style: groove; } <div id="DIV1">SOME SAMPLE TEXT</div>
We then created a button “Change Top Style” that will execute changeTopStyle() method on being clicked by the user −
<button onclick="changeTopStyle()">Change Top Style</button>
The changeTopStyle() method gets the div element with id “DIV1” using getElementById() and sets its borderTopStyle style property to dashed. This change is then reflected in the paragraph with id “Sample” by displaying the given text using its innerHTML property.
function changeTopStyle(){ document.getElementById("DIV1").style.borderTopStyle="dashed"; document.getElementById("Sample").innerHTML="The Top border style is now changed"; }