ontouchstart , ontouchmove and ontouchend controlled in the same way as onclick , onmousemove , etc.
You can apply listeners in the <script> or directly in the html element.
JavaScript Only
var back = document.getElementById("back-button-id"); back.ontouchstart = function( event ) {
Using the HTML tag and callbacks
1) Declare your Javascript callbacks to replace the css class for any state
function onclickCallback( event ) { // do something } function ontouchstartCallback( event ) { event.target.className = 'selected'; } function ontouchendCallback( event ) { event.target.className = 'normal'; }
2) Put callbacks in the anchor tag (I suggest using a DIV instead of A )
<div class="normal" onclick="onclickCallback( event );" ontouchstart="ontouchstartCallback( event );" ontouchend="ontouchendCallback( event );">Back</div>
Edit 1: to prevent hilight from freezing while scrolling
Try adding the ontouchmove handler
ontouchmove="ontouchmoveCallback( event );"
Then declare a handler function that changes the css class
function ontouchmoveCallback( event ) { event.target.className = 'normal'; }
Hope this helps! Ciao.
source share