On 08/08/06, Michael Fuerst <[EMAIL PROTECTED]> wrote:
> On Tue, August 8, 2006 17:28, Sam Collett said:
>
> >> var myClickFunction =  function()
> >> {
> >> $(this).toggleClass("backcolor2");
> >> }
> >>
> >> var myDblClickFunction =  function()
> >> {
> >> alert('DoubleClick');
> >> }
> >>
> >> both are bind to the same object. When I do a click on the object, the
> >> myClickFunction function is executed. When I do a double click, first
> >> the
> >> myDblClickFunction  is executed, than the myClickFunction function. Why?
> >> Is there a way, that on a double click only the myDblClickFunction  is
> >> executed?
> >>
> >> I'm using the stable version of jQuery.
> >>
> >> Michael
> >>
> >
> > This may work:
> >
> > var myDblClickFunction =  function(e)
> > {
> > e.stopPropagation();
> > alert('DoubleClick');
> > }
> >
>
> Thanks for your help, but this doesn't change anything, still both
> functions are executed... any other ideas?
>
> Michael
>
>

Now that I think about it, click will always fire, as you need to
click before you double click.
I have used stopPropagation before, but that does not seem to work
with click events. However, you can use setTimeOut on the click event
and cancel it in the double click event (although I haven't managed to
get it working consistently in Firefox):

var clickTimer;
var myClickFunction =  function(e)
{
        var doClick = function()
        {
                alert('Click');
        }
        clickTimer = window.setTimeout(doClick, 300);
}
        
var myDblClickFunction =  function(e)
{
        window.clearTimeout(clickTimer);
        alert('Double Click');
}

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to