-1

I have four divs in my html page something like this: the working fiddle implementation is here: http://jsfiddle.net/GxaCK/3/

 <div class="first">
    <p> First </p>
    </div>
    <div class="second">
    <p> Second </p>
    </div>
    <div class="third">
    <p> Third </p>
    </div>
    <div class="fourth">
    <p> Fourth </p>
    </div>

and then the jquery like this:

$(function() {
    var firstCnt = 0,
        secondCnt = 0,
        thirdCnt = 0,
        fourthCnt = 0;
    $(".first").live("click", function(){
        firstCnt += 1;
        $(".first p").text(firstCnt);
    });

     $(".second").live("click", function(){
        secondCnt += 1;
        $(".second p").text(secondCnt);
    });

});

now given this, i can do firstCnt%2 to get if the div was clicked for even or the odd number of times.

I have the following doubt: 1. is this a goodway of implementation, in a project? 2. is there anything like even odd selector for clicks as well, as exists in css3

user993563
  • 18,601
  • 10
  • 42
  • 55

1 Answers1

1

For even odd..you can use toggle. See updated jsfiddle here.

Brij
  • 6,086
  • 9
  • 41
  • 69