Reputation: 65
I want to mark the text I have selected using the taphold event. See the following code:
$(function () {
$('body').bind('taphold', function (e) {
$(this).addClass('highlighted');
e.stopImmediatePropagation();
return false;
});
});
But $(this) return the body, how can I get the selected content?
Upvotes: 1
Views: 431
Reputation: 2659
$(document).delegate('Here it should be the text selector like id or class name ', 'taphold', function (e) {
$(this).addClass('highlighted');
e.stopImmediatePropagation();
return false;
});
Hope this is helpful.
Upvotes: 0
Reputation: 87073
As you bind the event with the body
so $(this)
will return the body
, but e.target
will return your target element on which you fire you event.
$(function () {
$('body').bind('taphold', function (e) {
$(e.target).addClass('highlighted'); // use e.target instead of this
e.stopImmediatePropagation();
return false;
});
});
Upvotes: 1