<section>
  <div id="red" draggable="true">
    <span>R</span>
  </div>
  <div id="yellow" draggable="true">
    <span>Y</span>
  </div>
  <div id="green" draggable="true">
    <span>G</span>
  </div>
</section>

<p id="clicked">Click a box</p>
div[draggable] {
  width: 2em;
  height: 2em;
  line-height: 2em;
  margin: 1em;
  text-align: center;
  font-weight: bold;
  cursor: move;
}

#red {
  background: red;
}
#yellow {
  background: yellow;
}
#green {
  background: green;
}
const preview = evt => {
    const color = evt.target.id;
    document.querySelector('#clicked').textContent = `Clicked ${color}`;
};

document.querySelector('section').addEventListener('click', preview);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.