The borderColor
property sets or gets the
an element's border's color.
This property can take from one to four values:
border-color:red green blue pink;
is equal to
border-color:red green blue;
is equal to
border-color:red green;
is equal to
border-color:red;
is equal to
borderColor |
Yes | Yes | Yes | Yes | Yes |
Return the borderColor property:
var v = object.style.borderColor
Set the borderColor property:
object.style.borderColor=color|transparent|initial|inherit
Value | Description |
---|---|
color | Set the border color. Default color is black |
transparent | Set border color to transparent. Default value |
initial | Set to default value |
inherit | Inherit from parent element. |
Default Value: | black |
---|---|
Return Value: | A string representing the border-color property |
CSS Version | CSS1 |
The following code shows how to use .Change the color of the four borders of a <div> element to red:
<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {<!-- w w w.j a v a 2 s.com-->
border: thick solid blue;
}
</style>
</head>
<body>
<div id="myDiv">This is a div.</div>
<br>
<button type="button" onclick="myFunction()">Change color of the four borders</button>
<script>
function myFunction() {
document.getElementById("myDiv").style.borderColor = "red";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to use .Change the color of the top and bottom border to green, and left and right border to purple, of a <div> element:
<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {<!--from w ww . j a v a 2 s. c o m-->
border: thick solid blue;
}
</style>
</head>
<body>
<div id="myDiv">This is a div.</div>
<br>
<button type="button" onclick="myFunction()">Change color of the four borders</button>
<script>
function myFunction() {
document.getElementById("myDiv").style.borderColor = "green purple";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to use .Return the border color of a <div> element:
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j ava 2 s.c om-->
<div id="myDiv" style="border:thick solid green">This is a div.</div>
<br>
<button type="button" onclick="myFunction()">Return border color</button>
<script>
function myFunction() {
alert(document.getElementById("myDiv").style.borderColor);
}
</script>
</body>
</html>
The code above is rendered as follows: