When you set a counter in a jQuery plugin it will be set per instance of the plugin. For instance
$.myPlugin(\".one\");
$.myPlugin(\".two\");
$.myPlugin = funct
Use .data()
Try this example:
$.myPlugin(".one");
$.myPlugin(".two");
$.myPlugin = function (el) {
$(el).on('click', function () { // using .on instead of .click to handle dynamicaly added elements
var counter = parseInt($(this).data('counter')); // using .data() function of jquery to get value from element, it uses data-counter attribute
counter++; // iterating
$(this).data('counter', counter); // setting back counter with iterated value
});
};