JSFiddle - React, Tailwind, and code Playground

by superj80820

HTML

<body>
  <button id="A">A</button>
  <button id="B">B</button>
</body>

JavaScript

function alertC () {
  if (Object.keys(mouseDatas.A).length === 0 || Object.keys(mouseDatas.B).length === 0) return
  window.alert(`Alert C. A button x is ${mouseDatas.A.screenX}. B button x is ${mouseDatas.B.screenX}`)
  mouseDatas.A = {}
  mouseDatas.B = {}
}

const mouseDatas = {
  A: {},
  B: {},
}

document.getElementById('A').addEventListener('click', mouseData => {
  mouseDatas.A = mouseData
  window.alert('Alert A')
  alertC()
})
document.getElementById('B').addEventListener('click', mouseData => {
  mouseDatas.B = mouseData
  window.alert('Alert B')
  alertC()
})