I have some code that generally works, except on iPhone. When the window loads, this function is called. When I have the event as click
, it works just fine on desktop, but not on mobile. I've tried looking around for solutions for mobile, and touchstart
seems to be the recommended solution. But, though it works on emulators, it doesn't work on iPhone (tested on the latest OS version). Am I missing something?
function addXClassOnClick() {
var els = document.getElementsByClassName('item');
Array.prototype.forEach.call(els, function(el) {
el.addEventListener('touchstart', function() {
el.parentElement.classList.toggle('x');
}, false);
});
}
Thanks in advance!