Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  173] [ 2]  / answers: 1 / hits: 36178  / 15 Years ago, wed, july 1, 2009, 12:00:00

How is this done?


More From » jquery

 Answers
47

This is a good question, and I actually don't think it can be done easily. (Some discussion on this)



If it is super duper important for you to have this functionality, you could hack it like so:



function singleClick(e) {
// do something, this will be the DOM element
}

function doubleClick(e) {
// do something, this will be the DOM element
}

$(selector).click(function(e) {
var that = this;
setTimeout(function() {
var dblclick = parseInt($(that).data('double'), 10);
if (dblclick > 0) {
$(that).data('double', dblclick-1);
} else {
singleClick.call(that, e);
}
}, 300);
}).dblclick(function(e) {
$(this).data('double', 2);
doubleClick.call(this, e);
});


And here is an example of it at work.



As pointed out in the comments, there is a plugin for this that does what I did above pretty much, but packages it up for you so you don't have to see the ugly: FixClick.


[#99211] Friday, June 26, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austenjordang

Total Points: 544
Total Questions: 112
Total Answers: 112

Location: Monaco
Member since Sun, Jan 16, 2022
2 Years ago
;