2

Is there a way to acquire the actual current cursor style regardless of various overlays, overlaps, pseudo-elements and pseudo-classes?

Experiment sandbox here: https://codesandbox.io/s/loving-shaw-3c2zl?file=/src/styles.css

el.addEventListener('click', function(ev) {
  const style = window.getComputedStyle(ev.target).cursor
  console.log(ev.target, style)
})
div.Two:hover { // reports 'grab' on click
  cursor: grab;
}


div.Two::before {
  cursor: crosshair; // reports 'auto' on click
}

This Q/A doesn't address this specifically: how to use javascript get current cursor style from browser

customcommander
  • 17,580
  • 5
  • 58
  • 84
Qwerty
  • 29,062
  • 22
  • 108
  • 136
  • Pseudos aren't part of the DOM, so this isn't possible. – mfluehr May 19 '20 at 12:46
  • I was trying it also by detecting whether user interacts with element or its pseudo-element and then reading the `getComputedStyle(ev.target, '::before')`, but it's not possible to tell: https://stackoverflow.com/q/61876248/985454 – Qwerty May 19 '20 at 18:39

0 Answers0