How do I change the font of a javascript variable?

前端 未结 3 1234
有刺的猬
有刺的猬 2021-01-24 06:05

I am trying to make a game similar to cookie clicker. This is part of my code:

3条回答
  •  失恋的感觉
    2021-01-24 07:01

    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);
    }
    
    

    Attribution: random color creation by Paul Irish

提交回复
热议问题