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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

So, if I click once, that's the ONLY event that will register? In other words, once clicked, jquery won't look for other non-single click events?
No, both will have registered.
That explains it! In my "real" code, my alert was getting in the way.
yeah, that's true. You got it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.