How do I make different texts to appear in after clicking x-times?

Posted by Sebastian Lindén on Stack Overflow See other posts from Stack Overflow or by Sebastian Lindén
Published on 2012-12-02T10:32:27Z Indexed on 2012/12/02 11:04 UTC
Read the original article Hit count: 168

Filed under:
|
|

I want to show some text within a class for each click but keep the clicky-class. Shortly, if you click 2 times, you will get a div-text "You clicked two times", you will still be able to click a third time, then you will get "You clicked three times", until the fifth time when everything will hide. Is there any simpel way to do this? I tried with this but couldn't get it to work.

var clicks = 0;
$('.clicky').on('click', function()
    {
    clicks++;
        if(clicks >= 3)
        {
        $(this).add($('.background')).add($('.hello'));
        }

        else(clicks >= 5)
        {
        $(this).add($('.background')).hide();
        }
        });?

http://jsfiddle.net/sLAzY/ This is a working example of the hide function.

Hope you understand what I mean
Have a nice day!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery