background change sample

#00ff00


const b = document.getElementById('b')
const r = document.getElementById('r')
const c = document.querySelector('[name="theme-color"]')
b.addEventListener('click', () => {
  const randomColor = '#' + Math.random().toString(16).slice(-6)
  r.textContent = randomColor
  c.setAttribute('content', randomColor)
  document.body.style.background = randomColor
})

元記事を表示する