Search code examples
jquerycsshtmltouch

ontouchstart and ontouchend in jquery?


I am currently using the following for every element I want to change the class of on touch:

ontouchstart="$(this).addClass('select');" ontouchend="$(this).removeClass('select');"

I was wondering if there is something like this?:

$("#element").touchstart(function(){
    $(this).addClass('select');
},
function(){
   $(this).removeClass('select');
});

That I would be able to list all the elements that I want to have this property. I have tried so many things and cant get it to work.


Solution

  • I ended up just using this:

    $('#nav li').bind('touchstart', function(){
        $(this).addClass('select');
    }).bind('touchend', function(){
        $(this).removeClass('select');
    });