I have a JS code that adds event listeners for mouse action. I would like to add the same for touch to support mobile devices. I've attempted to do something like this:
var i = 0;
let loc = document.querySelectorAll("a[data-lat]");
loc.forEach(function(node) {
node.addEventListener("mouseenter", locOver); // old working code
node.addEventListener("touchstart", locOver); // added for touch support
node.addEventListener("mouseleave", locOut); // old working code
node.addEventListener("touchend", locOut); // added for touch support
node.id = i++;
});
Unfortunately nothing happens. I guess this would be too easy, hah? I'm trying to do it in plain vanila JS.