I don't think it's worth a whole plugin to to this - it is relatively
simple to add a counter to the toggle event functions, and to use the
data object to store your counts.

Eg:

$('a.toggle').toggle( function() {
    $(this).data('count', 1 + ( $(this).data('count') || 0 ) );
    $(this).css('color', 'red');
}, function() {
    $(this).css('color', 'green');
});

Now, every time I turn a 'toggle' link red, it will increment the
'count' data attached to the element.

If you're using it a lot, make a 'count' extension:

$.fn.extend({ count: $(this).data('count', 1 + ( $(this).data('count')
|| 0 )) });

Now, to count every toggle (ie, to red or green) you could do:

$('a.toggle').toggle( function() {
    $(this).count();
    $(this).css('color', 'red');
}, function() {
    $(this).count();
    $(this).css('color', 'green');
});

At any time I could list all the counts for these elements by:

$('a.toggle').each(function(){
    alert( $(this).text + ' was clicked ' + ( $(this).data('count') ||
0 ) + ' times!' );
});

Much easier that binding new events and trying to manage vars.

On Apr 29, 8:00 am, motob <[EMAIL PROTECTED]> wrote:
> It is possible, but has to me manually recorded by you. The best way I
> can think of is to use the meta data plugin (http://plugins.jquery.com/
> project/metadata). You'll need to attach a click event onto each link
> you want tracked, then you'll need to increment a counter and store
> that counter as meta data for each link.
>
> On Apr 28, 1:24 pm, Leanan <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hey guys.
>
> > I was curious if it was possible to query how many times something
> > that has toggle bound to it has been clicked.  Is this possible?- Hide 
> > quoted text -
>
> - Show quoted text -

Reply via email to