@Alex is correct, all you need to do is replace func(); at func.call(this); and it will work. However, I would like to point out that you make 2 redundant calls to the jQuery constructor in your plugin:
$.fn.touchBind = function(func) { //this already refers to a jQuery object this.live('touchmove', function() { //this refers to a DOM element inside here $(this).addClass('dragged'); }); //this already refers to a jQuery object this.live('touchend', function() { //this refers to a DOM element inside here if ($(this).hasClass('dragged') == false) { func.call( this ); } }); return this; }
You can check it as follows:
$.fn.whatIsThis = function(){ return "jquery" in this ? "jQuery object" : "Something else"; };
And then:
console.log( $("div").whatIsThis() );
Esailija
source share