Random predefined background color and text color on 2 divs

前端 未结 4 701
花落未央
花落未央 2020-12-11 09:27

I am looking to create a Jquery script that will randomly choose a colour from a list of 10, and then apply it as a background color to one div, and the color of a h1 tag. <

4条回答
  •  忘掉有多难
    2020-12-11 10:15

    May be this can help:
    Changing colors of a DIV

    Here is the JS of the code for an overview of approach that i used! JS:

    setInterval(function () { 
      document.getElementById("fancy").style.background= '#'+Math.floor(Math.random()*16777215).toString(16);
      document.body.style.background= '#'+Math.floor(Math.random()*16777215).toString(16); 
    }, 1000);
    

    Though this post is little old but it may be of some use in context of this question!!

提交回复
热议问题