Javascript String genRandomColor()

Description

Javascript String genRandomColor()


function genRandomColor () {
  var letters = '0123456789ABCDEF'.split('')
  var color = '#'
  for (var i = 0; i < 6; i++ ) {
    color += letters[Math.floor(Math.random() * 16)]
  }//w  ww . ja  v  a2 s  .  c o m
  return color
}

const items = document.querySelectorAll('.item')

Array.prototype.forEach.call(items, function (box) {
  box.addEventListener('mouseover', function () {
    this.style.background = genRandomColor()
  })
})



PreviousNext

Related