0

I've been trying to add separate click and double-click events to a span tag such as:

    $( document ).ready(function(){

    $("span").dblclick(function(){alert("b");});
    $("span").click(function(){alert("a");});

     });

After much (much!) headbanging, I found the solution here. To be honest, it seems a bit surprising that jquery doesn't do this automatically. Can someone provide an example as to why a person wouldn't want them to be bound separately?

Community
  • 1
  • 1
Eric
  • 1,209
  • 1
  • 17
  • 34

1 Answers1

1

Actually, jquery does bind them separately.

It also works correctly.

You have to use console.log since alert disturbs the code execution.

What happens on a double click?

When you use console.log you'll get 2 a since a double click has 2 clicks

and 1 b since only a single double click.

What happens on a single click?

Only .click() will be executed.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95