Examples

Change Random Colors

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>canvas</title>
</head>
​
<body>
<div id="demo">I love you!</div>
<button onclick="changeVal();">click me</button>
<script>
function changeVal(){
var obj=document.getElementById("demo");
var r = Math.floor(Math.random()*255);
var g = Math.floor(Math.random()*255);
var b = Math.floor(Math.random()*255);
var color = "#"+r.toString(16)+g.toString(16)+b.toString(16);
if(obj.innerHTML=="I love you!"){
obj.innerHTML="I hate you!";
obj.style.color = color;
}else if(obj.innerHTML=="I hate you!"){
obj.innerHTML="I love you!";
obj.style.color = color;
}
}
</script>
</body>
</html>