<button id="button">change color</button>
<div id="box"></div>
button{
  margin-bottom:1rem;
}

#box{
  background:#c00;
  width:250px;
  height:200px;
}
let button = document.getElementById('button');
let box = document.getElementById('box');

button.addEventListener("click", function() {
  changecolor('#0cc');
}, false);

function changecolor(code) {
   box.style.backgroundColor = code;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.