Change background to random colors on click - Javascript/jQuery -


i'm trying change body's background color random color every time nav-bar link clicked.

i got random color gets changed first time link clicked - when different link clicked, nothing changes.

any tips?

html:

    <div class="nav">       <ul id="show">         <li id="link1"><a href="#portfolio">portfolio</li></a>         <li id="link2"><a href="#about">about</li></a>         <li id="link3"><a href="#email">contact</li></a>         <hr/>       </ul>     </div> 

js:

$(function() {       var colors = ['red', 'blue', 'green', 'grey'];       var randcolor = colors[math.floor(math.random()*colors.length)];       $('.nav a').click(function() {          $('body').css('background-color', randcolor);      }); }); 

because generate 1 random number , keep using it, move inside of click method.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -