0
Q:

change the color of text in javascript

 document.getElementById("myH2").style.color = "#ff0000";

document.getElementById("myP").style.color = "magenta";

document.getElementById("myDiv").style.color = "lightblue"; 
2
document.getElementById("yourInputID").style.color = 'the color of your choice';
1
element.style.color = '#f0f';
4
<!DOCTYPE html>
<html>
<head>
<script>
function display()
{
var col=document.getElementById("demo");
col.style.color="#FF0000";
}
</script>
</head>
<body>

<h1>My First JavaScript</h1>
<p id="demo">click on the button below.....</p>

<button onclick="display()">Display</button>

</body>
</html>
1

New to Communities?

Join the community