Example

by Guillaume Lafarge

HTML

<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/elementFromPoint -->

<div style="padding:0;background:violet;color:white">Test</div>
<p id="para1">Some text here</p>
<button onclick="changeColor('blue');">Blue</button>
<button onclick="changeColor('red');">Red</button>

JavaScript

function changeColor(newColor) {
  elem = document.elementFromPoint(10, 20);
  elem.style.color = newColor;
}