color Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:color

Description

The color property sets or gets the color of the text.

Property Values

Value Description
color Sets the color of the text.
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: not specified?
Return Value: A String, representing the text-color of an element
CSS VersionCSS1

Set the text-color for different elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="color:red;">This is an example paragraph.</p>

<button type="button" onclick="myFunction()">Return text color of p</button>

<script>
function myFunction() {/*  ww  w  .  j ava  2 s .c  o m*/
    document.getElementById("myP").style.color = 'blue';
}
</script>

</body>
</html>

Related Tutorials