I got a Javascript function that changes between two CSS classes for a button (it changes its background color) when the button is clicked.
<button id="div" class="class1" onclick ="change();">ON / OFF</button>
function classToggle() {
this.classList.toggle('class1');
this.classList.toggle('class2');
}
document.querySelector('#div').addEventListener('click', classToggle);
In know that the 'click' event will not work on touch devices, but i have tried with 'touchastart' and 'touchend' but nothing seems to be working.
I guess the problem is that i cant figure out where to specify the touch friendly addeventlistener??
I can not figure out why, so i hope someone more knowledgeable can help :-)
Best regards