I have a parent div with 4 child elements inside. I want to trigger the touchmove event when I touch one of the span elements and move my finger. However, if I move my finger outside of the current span element while still pressing, I want the event to stop.
I've attempted to achieve this by checking if I'm touching a span element or another element, but so far it hasn't been successful. Once I press and move my finger, I can't seem to stop the event until I release my finger.
document.querySelector("#parent").addEventListener('touchmove', (e) => {
console.log(`pressed ${e.target.getAttribute('data-dir')}`)
});
<div id="parent">
<span data-dir="3">↑</span>
<span data-dir="0">→</span>
<span data-dir="1">↓</span>
<span data-dir="2">←</span>
</div>