I am trying to make a game similar to cookie clicker. This is part of my code:
You can add a function that is called on click which can update your css. Try this
<button onclick="myFunction()"> Click me </button>
function myFunction()
{
document.getElementById('clickCount').setAttribute("class", "style1");
}
Here is some more info on .setAttribue: https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
Add some CSS to style the element:
<style>
#clickCount {
color: red;
font-family: Gill Sans Extrabold, sans-serif;
}
</style>
Here's a solution giving your number a random new color on every click. I've changed the html from inline javascript to using an eventListener, which is what you want to use in real life
var clicks = 0;
document.getElementById("push").addEventListener("click", updateClickCount);
function updateClickCount() {
clicks++;
var el = document.getElementById("clickCount");
el.innerHTML = clicks;
el.style.color = '#'+Math.floor(Math.random()*16777215).toString(16);
}
<button type="button" id="push">Click me for Cola!</font></button>
<div id="clickCount"></div>
Attribution: random color creation by Paul Irish