The borderTopColor
property sets or gets
the color of the top border of an element.
borderTopColor |
Yes | Yes | Yes | Yes | Yes |
Return the borderTopColor property:
var v = object.style.borderTopColor
Set the borderTopColor property:
object.style.borderTopColor='color|transparent|initial|inherit'
Value | Description |
---|---|
color | Set the top border color. Default color is black |
transparent | Set the top border color to transparent |
initial | Set to default value. |
inherit | Inherit from parent element. |
Default Value: | black |
---|---|
Return Value: | A string representing the top border color |
CSS Version | CSS1 |
The following code shows how to change the top border color.
<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {<!-- ww w.ja v a2 s .c om-->
border: thick solid blue;
}
</style>
</head>
<body>
<div id="myDiv">This is a div.</div>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myDiv").style.borderTopColor = "red";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the top border color.
<!DOCTYPE html>
<html>
<body>
<!--from ww w . j a va 2s .com-->
<div id="myDiv" style="border-top:thick solid green">This is a div.</div>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
console.log(document.getElementById("myDiv").style.borderTopColor);
}
</script>
</body>
</html>
The code above is rendered as follows: